How can I put two queries in one mysql_query?

I am trying to do something like this:

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

but that will not work.

This is just an example, but my question is: how can I put two or more queries in the same mysql_query ?

+4
source share
4 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 is associated with the specified link_identifier.

But you may be interested in mysql i :: multi_query :

Executes one or more queries that are joined by a semicolon.
+12
source

You should use transactions for queries that should happen in atomic mode, which I suspect might be.

+4
source

This can be done using the MySQLi interface, in particular mysqli_multi_query (). http://ca3.php.net/manual/en/mysqli.multi-query.php

It should be noted that when using this function you need to be especially careful, since any SQL injection attack has a much wider effect.

0
source

or maybe you can try this ...

 $query1 ="UPDATE name SET money = money + 1;"; $query2 ="UPDATE surname SET money = money + 1"; mysql_query($query1,$query2) or die(mysql_error()); 
-3
source

All Articles