Under normal circumstances, PHP's mysql_query function is not able to execute multi-sentence CREATE table and other statements in bulk;
And some scenarios, such as having a SQL backup file, or creating a data table structure when the program is initialized, you need to batch execute the SQL statements in the file;
To solve this problem, you can use the Explode function to press '; ' The SQL statement is split into groups, and then the mysql_query can be executed by looping, because every SQL is '; ' The end of the number;
But consider that there may be entity symbols in the SQL statement Or, if you press '; ' It is easy to break the fire, so it is more reliable to use preg_split.
Sample environment:
SQL file:./thinkbjy.sql
$sql _array=preg_split ("/;[ \r\n]+/", file_get_contents ('./thinkbjy.sql ')); foreach ($sql _array as $k = + $v) {mysql_query ($v, $link); Echo mysql_error (). ' <br> '; }
Perform echo mysql_error (). ' <br> '; To see if there are errors;
650) this.width=650, "alt=" Bai Jun Remote Blog "src=" http://www.baijunyao.com/Upload/image/ueditor/20150712/1436709823663876. JPG "title=" Bai Jun Haruka Blog "/>
php function mysql_query batch execution of multiple SQL statements