mysql_query()
sends a unique query (multiple queries are not supported) .
That's the default behaviour.However there is a bypass for this.
However the result code of the first query alone will be given as output of mysql_query()
if you do this.
You just have to pass flag 65536 as mysql_connect's 5th parameter . the flag is defined in MySQL Client flags.
#define CLIENT_MULTI_STATEMENTS 65536 /* Enable/disable multi-stmt support */
#define CLIENT_MULTI_RESULTS 131072 /* Enable/disable multi-results */
So edit your mysql_connect()
code to match this:
mysql_connect($host, $username, $password, false, 65536);
Warning:
- You will get the result of
mysql_query($query)
for the first query only in the given $query
. You can try concatenating 131072
with 65536
for getting multiple results.
- This will not work on PHP < 4.3.0
- This will not work if
sql.safe_mode
is set as 1 in php.ini
Another alternative will be to use mysqli
instead of mysql
library. It supports $mysqli->multi_query()
and gives output within an array for each query.