If you need to parse * .sql in the body of php and execute queries sequentially, I use the following code:
$dump=file_get_contents('path/to/file.sql'); $q=''; $state=0; $coco=0; for($i=0;$i<strlen($dump);$i++){ switch($dump{$i}){ case '"': if($state==0) $state=1; elseif($state==1) $state=0; break; case "'": if($state==0) $state=2; elseif($state==2) $state=0; break; case "`": if($state==0) $state=3; elseif($state==3) $state=0; break; case ";": if($state==0) { //echo $q."\n;\n"; mysql_query($q); $q=''; $state=4; $coco++; } break; case "\\": if(in_array($state,array(1,2,3))) $q.=$dump[$i++]; break; } if($state==4) $state=0; else $q.=$dump{$i}; } echo'Выполнено запросов: '.$coco;
Naturally, after connecting to the database and selecting the database (you obviously know how to do this). I do not remember where I was taken, but it works properly.