php mysql 执行sql文件,使用php执行* .sql文件

博客内容讲述了如何在PHP中不使用mysql_query函数逐行执行,而是通过命令行客户端一次性运行包含多张表创建的SQL文件。建议使用`mysql -uUSERNAME -pDATABASENAME < FILE.SQL`命令,可能需要提供密码。此方法类似于phpMyAdmin的操作。

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.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值