Execute multiple queries against the database:
<?php $con = mysqli_connect ( " localhost " , " my_user " , " my_password " , " my_db " ) ; // Detect link if ( mysqli_connect_errno ( $con ) ) { echo " Failed to connect to MySQL: " . mysqli_connect_error ( ) ; } $sql = " SELECT Lastname FROM Persons ORDER BY LastName; " ; $sql .= " SELECT Country FROM Customers " ; // Execute multiple SQL statements if ( mysqli_multi_query ( $con , $sql ) ) { do { // Store the first result set if ( $result = mysqli_store_result ( $con ) ) { while ( $row = mysqli_fetch_row ( $result ) ) { printf ( " %sn " , $row [ 0 ] ) ; } mysqli_free_result ( $result ) ; } } while ( mysqli_next_result ( $con ) ) ; } mysqli_close ( $con ) ; ?>The mysqli_multi_query() function executes one or more queries against the database. Multiple queries are separated by semicolons.
mysqli_multi_query( connection,query ) ;
parameter | describe |
---|---|
connection | Required. Specifies the MySQL connection to use. |
query | Required. Specify one or more queries, separated by semicolons. |
Return value: | Returns FALSE if the first query fails. |
---|---|
PHP version: | 5+ |