开发者

SQL not updating multiple databases...whats wrong with my sql?

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='tim@dog.comsd', 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="'tim@dog.comsd'" 
WHERE开发者_如何转开发 rst_id = 90 AND rst_account_id = 1;


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜