php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9734 Error
Submitted: 2001-03-13 21:42 UTC Modified: 2001-04-25 18:52 UTC
From: ahmed at nmt dot edu Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.0.4pl1 OS: Unix
Private report: No CVE-ID: None
 [2001-03-13 21:42 UTC] ahmed at nmt dot edu
It seems like the DELETE query don't return any error so I have to test first for the existing of the element than if exist I'll delete it.


$db = mysql_connect("localhost", "root");
mysql_select_db("MY_DBASE", $db);
$Query="SELECT * FROM  MY_DATA WHERE MY_DATA.id=$id";
$result = mysql_query($Query, $db);
$rows = mysql_num_rows($result);
if ($rows>0) {
           $Query="DELETE FROM  MY_DATA WHERE MY_DATA.id=$id";
           mysql_query($Query, $db);
           print("<P align=center><font size=6 face=italic><strong>Recored 
                  $id deleted</strong></font>\n"); 
        }
else { 
           printf ("<P align=center><font size=6 face=italic><strong>
                      Error deleting record!:</strong> %s</font>\n", 
                      mysql_error ());
        }



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-25 18:52 UTC] cynic@php.net
watch this:

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| foo            |
+----------------+
1 row in set (0.00 sec)

mysql> select * from foo;
+--------------+
| bar          |
+--------------+
| 999999999.99 |
+--------------+
1 row in set (0.00 sec)

mysql> delete from foo where bar = 'hello';
Query OK, 0 rows affected (0.00 sec)

mysql>

the truth is that delete of 0 rows is NOT an error.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 09 09:01:26 2024 UTC