php文件在mysql中打开文件,PHP脚本在MySQL中导入文件

I have some code in my postwwwacct script which doesn't work, it doesn't import the sql file

shell_exec("cd /home/".$opts['user']."/public_html/sbans/sql/");

$command="mysql -u ".$opts['user']." -p".$opts['pass']." ".$opts['user']."_bans < data.sql";

shell_exec($command);

However after account creation i can manually run in ssh

cd /home/jason/public_html/sbans/sql/

mysql -u jason -pmypass jason_bans < data.sql

Which then works.

What is the problem with the php code in postwwwacct?

Sorry for re-editing your edit but the file does not have php extension

i manually call the php compiler by using

#!/usr/local/bin/php -q

解决方案

the problem is that shell_exec does cd and finishes so the command which would do the import with the sql is not found and failed.

try something like this :

$command="mysql -u ".$opts['user']." -p".$opts['pass']." ".$opts['user']."_bans < data.sql";

$output = shell_exec("cd /home/".$opts['user']."/public_html/sbans/sql/ && ".$command);

and if you want to see the result of your command just do

echo $output

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值