0

I'm trying to run one SQL command to update multiple databases. If I copy 'n paste sql code below directly into PHPMYADMIN it executes just fine, but when I run the sql through php it doesn't update?

If I run the updates for each database separately via my php script they both update fine, so I'm confused?

What am I doing wrong?

SQL Code:

UPDATE rst.users a, rst.user_type b 
SET a.first_name='Timsd',a.last_name='Lebaronsd',a.password='timsd',
 a.email='[email protected]', a.user_type_id='5',a.language_code='en_US', 
   a.timezone='Pacific/Midway', create_ts = '2010-07-16 12:33:31' 
WHERE a.user_type_id = b.user_type_id AND b.account_id = 1 AND a.users_id = 90; 

use externalusers; 

UPDATE externalusers.user 
SET fullname="'Timsd' 'Lebaronsd'", emailaddress="'[email protected]'" 
WHERE rst_id = 90 AND rst_account_id = 1;

3 Answers 3

3

mysql_query() and similar functions can't execute multiple statements for security reasons.
Use mysqli_multi_query() if you really want to execute multiple statements with single call.

P.S. It's not a PHP feature, but a feature of mysql C API.

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

2 Comments

Could I place the SQL inside a stored procedure, then in the 1st sql statement call the stored procedure that would do the update to the other database?
Ok, I dumped the stored procedures idea and decided to implement the mysqli solution. Works great now. Thanks for your help.
0

PHP has a security feature that prevents you from executing multiple queries with a single mysql_query() call. Unfortunately there's no way around it with the native mysql_* functions.

However I believe you can do it if you use PDO or MySQLi. I highly recommend PDO.

2 Comments

Could I place the SQL inside a stored procedure, then in the 1st sql statement call the stored procedure that would do the update to the other database?
you could or you could make two database connections.
0

To add to answers from others its important to say that you are not actually executing a single SQL statement but 2 (or actually probably 3), one after the other. PHPMYADMIN is simply breaking them on ; and executing them in sequence.

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.