簡體   English   中英

MySQLi編寫的語句沒有返回任何內容

[英]MySQLi prepared statement not returning anything

我試圖從文字query調用轉換為預准備語句。

我班上有以下功能:

public function read ($identifier) {
    $stmt = static::$mysqli->prepare('SELECT * FROM `table` WHERE `id` = ?;');
    $stmt->bind_param('i', $identifier);
    $stmt->execute();

    var_dump($stmt->num_rows);
}

我從phpMyAdmin知道數據庫中有一行id為1,但如果我調用read(1); num_rows為0。

但是,如果我使用這個邏輯:

public function read ($identifier) {
    $result = static::$mysqli->query('SELECT * FROM `table` WHERE `id` = '.(int) $identifier.';');
    var_dump($result->num_rows);
}

我得到1而不是。

嘗試調用$stmt->store_result(); execute()調用之后。
執行后結果尚未存儲在內存中,您將需要獲取所有行或調用store_result()以獲取num_rows變量以顯示受影響的實際行數。

暫無
暫無

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

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