mysqli_multi_query 处理 InnoDB 上的 MySQL 事务 :-)
<?php
$mysqli = mysqli_connect( "localhost", "owner", "pass", "db", 3306, "/var/lib/mysql/mysql.sock" );
$QUERY = <<<EOT
START TRANSACTION;
SELECT @lng:=IF( STRCMP(`main_lang`,'de'), 'en', 'de' )
FROM `main_data` WHERE ( `main_activ` LIKE 1 ) ORDER BY `main_id` ASC;
SELECT `main_id`, `main_type`, `main_title`, `main_body`, `main_modified`, `main_posted`
FROM `main_data`
WHERE ( `main_type` RLIKE "news|about" AND `main_lang` LIKE @lng AND `main_activ` LIKE 1 )
ORDER BY `main_type` ASC;
COMMIT;
EOT;
$query = mysqli_multi_query( $mysqli, $QUERY ) or die( mysqli_error( $mysqli ) );
if( $query )
{
do {
if( $result = mysqli_store_result( $mysqli ) )
{
$subresult = mysqli_fetch_assoc( $result );
if( ! isset( $subresult['main_id'] ) )
continue;
foreach( $subresult AS $k => $v )
{
var_dump( $k , $v );
}
}
} while ( mysqli_next_result( $mysqli ) );
}
mysqli_close( $mysqli );
?>