簡體   English   中英

在PHP和MySql編程中,如何在一個語句中執行3個以上的查詢?

[英]In PHP & MySql programming how to executive more then 3 queries in a single statement?

我想在一個語句中執行3個以上的查詢。 有可能嗎?

我需要將值插入表中,選擇整個表來計數用戶。

是否可以在單個語句中完成所有這些操作。

謝謝

您只能使用mysqli_multi_query()在mysqli中使用3個以上的查詢,但是mysql不支持它。

示例代碼:

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

相應地更改它。 它顯示了使用mysqli進行操作的多查詢。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM