簡體   English   中英

通過mysqli :: query中的變量傳遞null

[英]Pass null via a variable in mysqli::query

我有一個特殊情況,需要使用mysqli :: query而不是mysqli :: prepare。 我正在嘗試通過變量將null傳遞給存儲過程。 以下與准備好的語句配合使用:

$val = null;
$stmt = $this->db->prepare('CALL my_stored_procedure(?, ?)');
$stmt->bind_param('ii', $this->id, $val);
etc...

不適用於查詢:

$val = null;
$qry = $this->db->query("CALL my_stored_procedure($this->id, $val)");
etc...

結果是:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1, )'

我可以明確通過null ok,但這對我沒有好處。

同樣,在這種情況下,我無法使用准備好的語句。 有沒有辦法將null傳遞給mysqli查詢?

您不能使用以下語句:

$procedureArguments = '$this->id, ' . ( is_null($val) ? 'NULL' : $val );
$qry = $this->db->query('CALL my_stored_procedure(' . $procedureArguments . ')');

暫無
暫無

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

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