PHP Classes

File: install/import.php

Recommend this page to a friend!
  Packages of Minh Tien   Noblesse CMS   install/import.php   Download  
File: install/import.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Noblesse CMS
Content management system with custom plugins
Author: By
Last change: Improve install, update to version 2.0
Date: 11 years ago
Size: 931 bytes
 

 

Contents

Class file image Download
<?php

function import($conn,$fileName = 'db.sql')
{

    if (file_exists($fileName)) {

        $conn->query("SET NAMES 'utf8';");


        $query = file_get_contents($fileName);

        preg_match_all('/CREATE.*?\;\n/is', $query, $creates);

        $total = count($creates[0]);

        for ($i = 0; $i < $total; $i++) {

            $conn->query($creates[0][$i]);
              if(isset($conn->error[5]))
              {
                throw new Exception($conn->error);
                      
              }            
        }

        preg_match_all('/INSERT.*?\;\n/is', $query, $creates);

        $total = count($creates[0]);

        for ($i = 0; $i < $total; $i++) {

            $conn->query($creates[0][$i]);
              if(isset($conn->error[5]))
              {
                throw new Exception($conn->error);
                      
              }              
        }

    }

    return false;

}

?>