在下面的php代碼中,準備語句會故意導致錯誤,以測試bind_param並執行,添加$ bikes。準備好的語句和bind_param錯誤處理
在execute函數中返回錯誤信息;但是,在bind_param中,雖然發生錯誤,但它不返回任何錯誤信息。
如何獲取bind_param中的錯誤信息?
$sqlQuery = "INSERT INTO the_cars (cars) VALUES (?)";
if($statement = $con->prepare($sqlQuery)){
if(!$statement->bind_param("s", $cars, $bikes)){ //bikes should not be here
$errors = $statement->error; //error is empty
};
if(!$statement->execute()){
$errors1 = $statement->error; // error: No data supplied for parameters in prepared statement
};
}else{
$errors = $con->error;
}
編輯:
PHP手冊似乎表明,在bind_param錯誤的處理方式。 查看文本的以下部分:實施例#3 INSERT製備一次,多次執行»/ *準備語句,階段2:結合並執行*/
http://php.net/manual/en/mysqli.quickstart.prepared-statements.php
這似乎也位置主張在一些職位。例如:
MySQLi prepared statements error reporting
不過,我做了一些嘗試,我從來沒有能夠得到一個說法錯誤的描述中bind_param。
我認爲你必須自己檢查一下。 – Sysix