I need to execute a .sql file which has about 48 tables to create. It is consisting of comments and sql commands which are ending in a ";". Is there a way to run these sql commands taking them to a single string and at once. I mean I need to run the whole file at once using php. I can execute that file line by line using mysql_query function. But I need to do is to execute all of them at once as same as in phpmyadmin.
Is there a way to do it. I need to do this using php. Can anyone help me please?
解决方案
You are looking for
An alternative would be to use the command line client:
mysql -u USERNAME -p DATABASENAME < FILE.SQL
You can probably use that with exec and/or system, but then you have to provide the password after -p. The above command will prompt you for it.
博客内容讲述了如何在PHP中不使用mysql_query函数逐行执行,而是通过命令行客户端一次性运行包含多张表创建的SQL文件。建议使用`mysql -uUSERNAME -pDATABASENAME < FILE.SQL`命令,可能需要提供密码。此方法类似于phpMyAdmin的操作。
3856

被折叠的 条评论
为什么被折叠?



