|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62348 mysqli query does not return false on DELETE
Submitted: 2012-06-18 00:14 UTC Modified: 2013-02-18 00:35 UTC
From: valentiny510 at yahoo dot es Assigned:
Status: No Feedback Package: MySQLi related
PHP Version: 5.4.4 OS: XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: valentiny510 at yahoo dot es
New email:
PHP Version: OS:


 [2012-06-18 00:14 UTC] valentiny510 at yahoo dot es
Honestly, i'm not realy sure if is php or mysql thing..
Look at the test script

NOTE: id 2 DOES NOT exists and MYSQL_REPORT_ALL does nor report anything :S

Test script:
mysqli_report( MYSQLI_REPORT_ALL );

$db = new mysqli('.', 'root', 'pass', 'database');

if (!$db->query('DELETE FROM sessions WHERE id = 2'))
    echo 'Cannot delete session: ', $db->error;
    echo 'DELETED';

Expected result:
Cannot delete session: "some error from mysqli"

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-18 07:13 UTC] adamjonr at gmail dot com
The mysqli query returns false for failed queries and true for successful queries 
that don't involve SELECT, SHOW, DESCRIBE or EXPLAIN (i.e., DELETE queries return 
true when "successful".) DELETE queries can impact 0, 1, or multiple rows, and 
their completion without error is, at least in the terms of the mysqli library, 
considered a success.

If you want to alter the flow of your script depending on whether a row has been 
deleted, you can use $mysqli->affected_rows to retrieve the number of rows 
impacted by the last DELETE, INSERT, or UPDATE statement:
 [2012-06-18 22:57 UTC]
Please try using this snapshot:
For Windows:

The query is successfull, een if no data is deleted/changed.
 [2012-06-18 22:57 UTC]
-Status: Open +Status: Feedback
 [2013-02-18 00:35 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 [2013-03-19 06:53 UTC] valentiny510 at yahoo dot es
cite from

"The IGNORE keyword causes MySQL to ignore all errors during the process of deleting rows. (Errors encountered during the parsing stage are processed in the usual manner.) Errors that are ignored due to the use of IGNORE are returned as warnings."

So mysql return some warnings if I dont use the word IGNORE..

Also say:
"For the single-table syntax, the DELETE statement deletes rows from tbl_name and returns a count of the number of deleted rows."

I wonder if is posible to return that number in the same query..
Will be easier without calling $db->affected_rows
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 18:01:35 2024 UTC