PHP shell_exec INSERT MySQL

时间:2011-05-10 15:37:45

标签: 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_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命令。

2 个答案:

答案 0 :(得分:2)

从mySQL文档中,这是一个可以实现您需要的示例。

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

我希望这会有所帮助。

答案 1 :(得分:0)

尝试引用'INSERT INTO [...skipped...] '