PHP shell_exec 插入 MySQL

发布于 2024-11-06 09:15:36 字数 1153 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゃ人海孤独症 2024-11-13 09:15:36

从 mySQL 文档中,这里有一个示例,可以满足您的需求。

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

我希望这有帮助。

From the mySQL documentation, here is an example that looks to accomplish what you need.

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

I hope this helps.

沒落の蓅哖 2024-11-13 09:15:36

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

Try to quote 'INSERT INTO [...skipped...] '

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文