mysqli::more_results
mysqli::next_result
MySQLi
PHP Manual

# mysqli::multi_query

# mysqli_multi_query

(PHP 5)

mysqli::multi_query -- mysqli_multi_query — Performs a query on the database

### Opis

Styl obiektowy

bool mysqli::multi_query ( string `$query` )

Styl proceduralny

bool mysqli_multi_query ( mysqli `$link` , string `$query` )

Executes one or multiple queries which are concatenated by a semicolon.

To retrieve the resultset from the first query you can use mysqli_use_result() or mysqli_store_result(). All subsequent query results can be processed using mysqli_more_results() and mysqli_next_result().

### Parametry

`połączenie`

  Tylko styl proceduralny: Identyfikator połączenia zwrócony przez mysqli_connect() lub mysqli_init()

`query`

  The query, as a string.

  Data inside the query should be properly escaped.

### Zwracane wartości

Returns `FALSE` if the first statement failed. To retrieve subsequent errors from other statements you have to call mysqli_next_result() first.

### Przykłady

Przykład #1 mysqli::multi_query example

Styl obiektowy

`<?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();
?>`

Styl proceduralny

`<?php
$link = mysqli_connect("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($link, $query)) {
do {
/* store first result set */
if ($result = mysqli_store_result($link)) {
while ($row = mysqli_fetch_row($result)) {
printf("%s\n", $row[0]);
}
mysqli_free_result($result);
}
/* print divider */
if (mysqli_more_results($link)) {
printf("-----------------\n");
}
} while (mysqli_next_result($link));
}
/* close connection */
mysqli_close($link);
?>`

Powyższe przykłady wyświetlą coś podobnego do:

    my_user@localhost
    -----------------
    Amersfoort
    Maastricht
    Dordrecht
    Leiden
    Haarlemmermeer

### Zobacz też:

- mysqli_use_result() - Initiate a result set retrieval
- mysqli_store_result() - Transfers a result set from the last query
- mysqli_next_result() - Prepare next result from multi_query
- mysqli_more_results() - Check if there are any more query results from a multi query

mysqli::more_results
mysqli::next_result
MySQLi
PHP Manual