PHP: stmt->execute() fails, but error is empty

家住魔仙堡 提交于 2019-12-08 07:30:42

问题


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;    
    }

(...)

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.

I also declared

error_reporting(E_ALL);

right after <?php, and

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

after each set of query. Still, no error is echoed back. What could be the problem? ~

UPDATE

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!


回答1:


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.

Following is the very beginning of the script:

<?php
    ini_set("display_errors", 1);
    ini_set("track_errors", 1);
    ini_set("html_errors", 1);
    error_reporting(E_ALL);
    // (...)


来源:https://stackoverflow.com/questions/23765428/php-stmt-execute-fails-but-error-is-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!