Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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
PHP shell_exec INSERT MySQL_Php_Mysql_Shell_Command Line_Wamp - Fatal编程技术网

PHP shell_exec INSERT MySQL

PHP shell_exec INSERT MySQL,php,mysql,shell,command-line,wamp,Php,Mysql,Shell,Command Line,Wamp,我正在尝试使用shell_exec(在localhost上)将一些数据插入表中 以下是我使用的代码: $shellExec = 'C:\wamp\bin\mysql\mysql5.1.36\bin\mysql -h localhost -u root mm_'.$acname.' INSERT INTO account (acct_name,start_date,active,name,address1,address2,postcode,telephone,website,email,vat_

我正在尝试使用shell_exec(在localhost上)将一些数据插入表中

以下是我使用的代码:

$shellExec = 'C:\wamp\bin\mysql\mysql5.1.36\bin\mysql -h localhost -u root mm_'.$acname.' INSERT INTO account (acct_name,start_date,active,name,address1,address2,postcode,telephone,website,email,vat_number,vat_amount,start_number,currency) VALUES("'.$company.'","'.$start_date.'","'.$active.'","'.$acname.'","'.$address1.'","'.$address2.'","'.$postcode.'","'.$telephone.'","'.$website.'","'.$email.'","'.$vat_number.'","'.$vat_amount.'","'.$start_number.'","'.$currency.'")';

shell_exec($shellExec);
其运行方式如下:

C:\wamp\bin\mysql\mysql5.1.36\bin\mysql -h localhost -u root mm_robdunne22 INSERT INTO account (acct_name,start_date,active,name,address1,address2,postcode,telephone,website,email,vat_number,vat_amount,start_number,currency) VALUES("sdfsdfy","10-05-2011","1","robdunne22","fsdfs","dfsd","sdf","3423423434sdfsdf","cvxcvdfg","gfgh55ydddd","sdfs","sdfgggaacc","1","pound")
在命令行上


这失败了-在命令行上,如果我运行它,它只会显示MySQL帮助信息。我认为问题在于登录MySQL和INSERT语句应该是分开的。如果我将它们拆分,它们可以正常工作,但是我不确定如何实现这一点-拆分为两个或作为一个shell命令。

尝试引用mySQL文档中的
'INSERT-into[…skipped…]。

,下面是一个看起来可以实现您所需功能的示例

mysql -u root -p --execute="SELECT User, Host FROM mysql.user"

我希望这会有所帮助。

为什么不使用php内置的mysql支持?在Windows中正确引用命令行参数已经是一项艰巨的任务。你想做的事情有一个名字:受虐狂。另外,当我们在做的时候,你应该看看准备好的报表,检查$company等是否被正确转义。最后,如果您在共享服务器上,您需要检查其他用户是否看不到您使用任务管理器执行的命令(我认为这就是它的名称;windows等效于top)。感谢您的回复@lvaro G。Vicario是正确的。我没能让它工作。