Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在MySQL中导入文件的PHP脚本_Php_Mysql_Cpanel - Fatal编程技术网

在MySQL中导入文件的PHP脚本

在MySQL中导入文件的PHP脚本,php,mysql,cpanel,Php,Mysql,Cpanel,我的postwwwacct脚本中有一些代码不起作用,它不导入sql文件 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); 在我脑海中,你确定data.sql文件位于所有不同用户的sq

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

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

在我脑海中,你确定data.sql文件位于所有不同用户的sql文件夹中吗?您还可以创建一个单独的bash脚本,并在脚本中调用它,这在我之前是有效的,您只需通过如下方式传入参数:

$t = shell_exec("path/command.sh '$opts['user']' '$opts['pass']' 2>&1");
echo $t
在bash脚本中,从下面开始获取变量: #!/bin/bash

 #Get variables needed

 user=$1
 pass=$2
然后,您可以继续使用这些变量作为任何普通bash变量,如果由于shell_exec命令末尾的2>&1,它仍然不适用于您,那么您可以更轻松地调试它


祝你好运

问题在于shell_exec执行cd并完成,因此将使用sql执行导入的命令找不到并且失败

试着这样做:

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

您遇到了什么错误?您有运行shell命令的权限吗?
echo$命令
若要查看其是否有效,我无法查看输出,因为此命令在帐户创建时通过cpanel运行其他shell命令正在工作,例如太多复制文件,因此它不应该是权限问题抱歉,但在手动运行shell命令时它不应该有空间,我需要键入-pmypass no space,为了让它工作,我正在使用以前的shell命令将sql文件复制到每个users dir,所以它肯定在那里。我想继续使用php,因为代码的其余部分是。我仍然强烈建议您在shell_exec命令之后添加2>&1。无论如何,它会打印错误,如果您回显$command,您将获得更多关于失败原因的信息
 #Get variables needed

 user=$1
 pass=$2
<?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);