简体   繁体   English

mysqli没有返回受影响的行

[英]mysqli isn't returning the affected rows

Can someone tell me what I'm doing wrong? 有人可以告诉我我在做什么错吗? I cannot get the affected rows returned after a row has been deleted. 删除一行后,我无法返回受影响的行。 The function always returns int(0) even though the delete action was preformed. 即使执行了删除操作,该函数也始终返回int(0)。 I read where I needed to clear or close the results which I have done but it still does not work. 我阅读了需要清除或关闭已完成结果的位置,但是仍然无法正常工作。 A debug shows this error: Command out of sync. 调试显示此错误:命令不同步。 The manual states that to overcome this, $result->free must be used. 该手册指出,要克服此问题,必须使用$ result-> free。 In my case, it doesn't work. 就我而言,它不起作用。

    $res = db::query("CALL deleteUser('$phone')");

    if($res !== 1) {
        echo 'failed';
    } else {
        echo 'success';
    }

This is the part of the function where the query does its thing. 这是函数执行查询的部分。

    if(self::$instance->query($query) === false){
        throw new exception("Failed");
    } return self::$instance->affected_rows;

When calling a stored procedure or function the int(0) is noting that the stored procedure exited without any errors. 调用存储过程或函数时, int(0)指出该存储过程已退出,没有任何错误。 You'll need to select the number of rows affected in the stored procedure then have your stored procedure return the rows affected via an output variable. 您需要选择存储过程中受影响的行数,然后让您的存储过程通过输出变量返回受影响的行。

When executing MySQL Stored Procedures in PHP , there are occasions where there is extra data being sent from the server that you have yet to retrieve. 在PHP中执行MySQL存储过程时 ,有时会从服务器发送一些尚未检索的 额外数据 This will cause the "Commands out of Sync" error. 这将导致“命令不同步”错误。 I can't remember exactly why, but I read this on the MySQL forums a long time ago. 我不记得确切的原因,但是很久以前我在MySQL论坛上阅读了这篇文章。 You can clean up your result data with something like this: 您可以使用以下方法清除结果数据:

while (self::$instance->next_result()) { }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM