PHP shell_exec 插入 MySQL
我正在尝试使用 shell_exec (在本地主机上)将一些数据插入到表中。
这是我正在使用的代码:
$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 命令。
I'm trying to insert some data into a table with shell_exec (on localhost).
Here's the code I'm using:
$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);
Which runs as:
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")
On the command line.
This fails - on the command line if i run this it just displays the MySQL help information. I think the problem is that logging into MySQL and the INSERT statement should be separate. They work fine if I split them, however I'm not sure how to make this work - either split into two or as one shell command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 mySQL 文档中,这里有一个示例,可以满足您的需求。
我希望这有帮助。
From the mySQL documentation, here is an example that looks to accomplish what you need.
I hope this helps.
尝试引用
'INSERT INTO [...skipped...]'
Try to quote
'INSERT INTO [...skipped...] '