1

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.

4
  • 4
    Why just don't use mysql support built into php? Commented May 10, 2011 at 15:45
  • Properly quoting command line arguments in Windows is already a daunting task. What you want to do has a name: masochism. Commented May 10, 2011 at 15:53
  • Also, while we're at it, you should look at prepared statements, and check that $company etc are properly escaped. Finally, if you are on a shared server, you need to check that other users can't see the commands you execute using the task manager (I think that's what it's called; the windows equivalent of top). Commented May 10, 2011 at 15:53
  • Thanks for the replies @Álvaro G. Vicario was right. Didn't manage to get this working. Commented May 11, 2011 at 10:15

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.