2

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

Phoenix Bird
  • 1,187
  • 1
  • 8
  • 22

2 Answers2

1

You can use more than 3 queries only in mysqli using mysqli_multi_query(), but mysql doesn't support it.

Deepika
  • 826
  • 6
  • 14
Winston
  • 1,758
  • 2
  • 17
  • 29
0

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.

Sankalp Singha
  • 4,461
  • 5
  • 39
  • 58