PHP脚本在MySQL中导入文件 [英] PHP script to import file in MySQL

查看:102
本文介绍了PHP脚本在MySQL中导入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的postwwwacct脚本中有一些代码不起作用,它不导入sql文件

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);

但是创建帐户后,我可以在ssh中手动运行

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

然后工作.

postwwwacct中的php代码有什么问题?

What is the problem with the php code in postwwwacct?

很抱歉,重新编辑您的编辑,但该文件没有php扩展名 我使用

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

推荐答案

问题是shell_exec会执行cd并完成操作,因此找不到与sql一起导入的命令,并且失败了.

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.

尝试这样的事情:

<?php
$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

echo $output

这篇关于PHP脚本在MySQL中导入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆