tags:

views:

41

answers:

3

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;
A: 

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.

Cfreak
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?
Ronedog
you could or you could make two database connections.
Cfreak
+3  A: 

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.

Naktibalda
Thanks...this will help.
Ronedog
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?
Ronedog
Ok, I dumped the stored procedures idea and decided to implement the mysqli solution. Works great now. Thanks for your help.
Ronedog
A: 

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.

Toby Allen