Dynamic Web Pages: deutschsprachiger PHP Knotenpunkt seit 1999

Dynamic Web Pages : deutschsprachiges PHP-Handbuch : mysqli-multi-query _

 
  PHP Journal  
  _  
 
<mysqli_more_results mysqli_next_result>
Letzte Aktualisierung: Thu, 17 Apr 2014
 

mysqli_multi_query

(PHP 5)

mysqli_multi_query

(no version information, might be only in CVS)

mysqli->multi_query -- Performs a query on the database

Description

Procedural style:

bool mysqli_multi_query ( mysqli link, string query )

Object oriented style (method):

class mysqli {

bool multi_query ( string query )

}

The mysqli_multi_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().

Rückgabewerte

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

Beispiele

Beispiel 1. Object oriented style

<?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->close();
       }
      
/* print divider */
      
if ($mysqli->more_results()) {
          
printf("-----------------\n");
       }
   } while (
$mysqli->next_result());
}

/* close connection */
$mysqli->close();
?>

Beispiel 2. Procedural style

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

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

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


<mysqli_more_results mysqli_next_result>
Letzte Aktualisierung: Thu, 17 Apr 2014
 


powered by Hetzner
top Alle Rechte vorbehalten. © Dynamic Web Pages 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 top

Werbung an/aus Werbung aus Werbung an