douyuliu9527 2016-03-24 10:54
浏览 51

MySQLi在函数失败时执行不返回false

I have a function to insert into a table, then insert into another with LAST_INSERT_ID and finally return the LAST_INSERT_ID. It works fine except that there is a foreign key that can make the function fail error 1452. This happens when I test with a bad foreign key in MySQLWorkbench with this query:

SELECT create_match(1,2);

However in PHP, if the function fails it still returns true.

    $query = "SELECT create_match(?,?)";
    if (!$stmt = $this->mysqli->prepare($query))
        error_log("CreateMatch() Failed to prepare statement: " . $this->mysqli->error . __FILE__ . " Line: " . __LINE__,0);
    else {
        $stmt->bind_param('ii', $gameID, $userID);
        $success = $stmt->execute();
        $stmt->bind_result($res);
        $stmt->fetch();
    }

$success is true even if the function failed. Why might this be and how can I detect if the function failed? I am weary about testing it in the function because I am returning an unsigned int and any number could be valid.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 wegame打不开英雄联盟
    • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
    • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
    • ¥30 eclipse开启服务后,网页无法打开
    • ¥30 雷达辐射源信号参考模型
    • ¥15 html+css+js如何实现这样子的效果?
    • ¥15 STM32单片机自主设计
    • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
    • ¥15 不小心不正规的开发公司导致不给我们y码,
    • ¥15 我的代码无法在vc++中运行呀,错误很多