Bug #62348 [Opn->Fbk]: mysqli query does not return false on DELETE
| From: | johannes@php.net | Date: | Mon, 18 Jun 2012 22:57:59 +0000 |
| Subject: | Bug #62348 [Opn->Fbk]: mysqli query does not return false on DELETE | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-171357@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62348&edit=1
ID: 62348
Updated by: johannes@php.net
Reported by: valentiny510 at yahoo dot es
Summary: mysqli query does not return false on DELETE
-Status: Open
+Status: Feedback
Type: Bug
Package: MySQLi related
Operating System: XP
PHP Version: 5.4.4
Block user comment: N
Private report: N
New Comment:
Please try using this snapshot:
http://snaps.php.net/php5.4-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
The query is successfull, een if no data is deleted/changed.
Previous Comments:
------------------------------------------------------------------------
[2012-06-18 07:13:30] 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.
http://www.php.net/manual/en/mysqli.query.php
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:
http://php.net/manual/en/mysqli.affected-rows.php
------------------------------------------------------------------------
[2012-06-18 00:14:46] valentiny510 at yahoo dot es
Description:
------------
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;
else
echo 'DELETED';
Expected result:
----------------
Cannot delete session: "some error from mysqli"
Actual result:
--------------
DELETED
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62348&edit=1