Reputation: 1247
i want to execute a more then 3 queries in a single statement. is is possible?
i need to insert the values into the table select entire table count the users.
is it possible to do all these in a single statement.
Thanks
Upvotes: 2
Views: 159
Reputation: 4546
Example code :
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT CURRENT_USER();";
$query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";
/* execute multi query */
if ($mysqli->multi_query($query)) {
do {
/* store first result set */
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_row()) {
printf("%s\n", $row[0]);
}
$result->free();
}
/* print divider */
if ($mysqli->more_results()) {
printf("-----------------\n");
}
} while ($mysqli->next_result());
}
/* close connection */
$mysqli->close();
?>
Change it accordingly. It shows multiquery in action using mysqli.
Upvotes: 0
Reputation: 1805
You can use more than 3 queries only in mysqli using mysqli_multi_query()
, but mysql doesn't support it.
Upvotes: 1