开发者

How to run series of SQL statements stored in a .text file in PHP?

I store such sqls in a text file:

insert into table ...;
...
insert into table ...;

How to executable all those statements with PHP? It seems mysql_query() can only execute 1 statement every time.

UPDATE

The reason I don't do it in command line like this

mysql -u your_user_name -p -D your_database_name < your_sql_file.txt;

is that it won't work when 开发者_StackOverflowthere's multi-byte characters in your_sql_file.txt, will get stuff like 梵天眼


$txt = file_get_contents('FILE.txt');
$queries = explode(';', $txt);
foreach($queries as $sql){
   mysql_query($sql)
}


  • open the file
  • read each line
  • use mysql_query()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜