Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I put two queries in one mysql_query?

Tags:

php

mysql

I'm trying to do something like this:

mysql_query("
  UPDATE name SET money = money + 1;
  UPDATE surname SET money = money + 1;
"); 

but it doesn't work.

It's just example, but my question is: How can I put two or even more queries in one mysql_query?

like image 677
good_evening Avatar asked Dec 09 '22 18:12

good_evening


2 Answers

http://docs.php.net/mysql_query says:

mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier .

But you might be interested in mysqli::multi_query:

Executes one or multiple queries which are concatenated by a semicolon.
like image 72
VolkerK Avatar answered Dec 13 '22 22:12

VolkerK


You should use transactions for queries that need to happen in an atomic fashion, which I suspect these may.

like image 29
Ignacio Vazquez-Abrams Avatar answered Dec 13 '22 23:12

Ignacio Vazquez-Abrams