PHP:stmt-> execute()失败,但错误为空 [英] PHP: stmt->execute() fails, but error is empty
问题描述
以下代码片段位于我的php文件中,该文件称为REST接口.
Following snippet is in my php-file, which figures as REST interface.
(...)
if ($stmt = $connection->prepare("INSERT INTO Resource VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")){
$stmt->bind_param("sssssssii", $email, $timestamp, $title, $desc, $lat, $lng, $alt, $full, $cat);
// 1)
if($stmt->execute()){
// insertion of Resource successful
// 2)
}else{
// insertion of Resource failed
echo "INSERTION_RESOURCE_FAILED";
$stmt->close();
die;
}
(...)
正确执行的先前版本没有两个额外的整数字段作为参数.我通过在其中放置回声来调试" php文件.在位置1)我没有收到回声,在位置2)没有收到.对我来说,这意味着stmt-> execute()失败.但是,如果失败了,为什么我也没有收到else块的回声?如何更好地调试此类问题?请注意,我检查了POST值,它们是正确的.
The previous version, which was executed correctly, hadn't the two additional integer fields as parameters. I "debugged" the php file by placing echos in there. At position 1) I received the echo back, at position 2) not. That means to me that the stmt->execute() fails. But if that fails, why I don't receive the echo of the else block neither? How can I better debug such issues? Note that I checked the POST values, they are correct.
我也宣布了
error_reporting(E_ALL);
紧接在<?php
和
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
每组查询后的
.尽管如此,没有错误回显.可能是什么问题呢? 〜
after each set of query. Still, no error is echoed back. What could be the problem? ~
更新
就像莱纳斯(Linus)提到的,那是失踪的display_errors()
.所以最后我发现这是一个外键问题.但是,由于您的回答,我终于可以调试PHP了!
Like Linus mentioned, it was the missing display_errors()
. So finally I found out that it was a issue with a foreign key. But thanks to your answer I am finally able to debug the php some pleasenter!
推荐答案
好,所以错误实际上是缺少display_errors()
.仅在声明它之后,脚本才返回错误的stackstrace.就我而言,这是一个与SQL有关的问题.
Ok so the error was in fact that the missing display_errors()
. Only after declaring it the script returned a stackstrace of the error. In my case, it was a SQL-related problem.
以下是脚本的开头:
<?php
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);
// (...)
这篇关于PHP:stmt-> execute()失败,但错误为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!