执行两个不同的查询并获取

时间:2011-03-24 06:46:02

标签: php

可以在mysql_query中执行两个不同的查询,并获取这两个查询的记录。

2 个答案:

答案 0 :(得分:1)

mysql_query不支持此

你可以用

mysqli::multi_query

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

答案 1 :(得分:0)

65536用于在mysql中运行多个查询,但我不确定这对你有帮助。但我用这个来调用php中的程序。

$con = mysql_connect('localhost','root','',false,65536); //65536 is used to fire multiple query.