mysql - How execute SQL file and inserting data into DATABASE TABLES using PHP -


i have sql file created database (named test) on localhost , want insert data database ( named server_db) via php script .

i tried , php script working fine , creating tables server_db database. values in tables not inserting ..... please help

my php code given below

<?php  class executer {    public $path="";     public function execute($path){     // mysql connectivity     $link = mysql_connect("localhost","root","");     mysql_select_db("server_db");      //file content     $content = file_get_contents($path);      //remove comments     $lines = explode("\n",$content);     $content = '';      foreach($lines $line){         $line = trim($line);         if( $line && !$this->startswith($line,'--') ){             $content .= $line . "\n";         }     }     //convert data array of queries     $content = explode(";", $content);     //run query     $total = $sucess=0;     foreach($content $command){         if(trim($command)){             $success = (mysql_query($command)==false ? 0 : 1);         }     } } public function startswith($string, $sym_com){     $length = strlen($sym_com);     return (substr($string, 0, $length) === $sym_com); }      } $path = "c:/xampp/htdocs/final/downloads/server_database_file.sql"; execute($path);  

i think need check sql text file encoding. because line delimiter each encoding not "\n". can try change "\r"


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -