php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38475 mysql_error doesn't reset after mysql_* func call
Submitted: 2006-08-16 18:03 UTC Modified: 2006-08-17 09:09 UTC
From: mirya at matrix dot ua Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.1.4 OS: FreeBSD6.1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mirya at matrix dot ua
New email:
PHP Version: OS:

 

 [2006-08-16 18:03 UTC] mirya at matrix dot ua
Description:
------------
Extract from mysql_error() php doc page:

"Note that this function only returns the error text from the most recently executed MySQL function (not including mysql_error() and mysql_errno())..."

I noticed that a error is not reset for mysql_fetch_*() call (server/client 5.0.22), mean if you perform mysql_query() for some data manipulation statement producing a error, then call mysql_fetch_*(), mysql_error() will return mysql_query() error message.

So the docs page is inconsistent with current mysql lib behaviour

Reproduce code:
---------------
mysql_connect('localhost', 'mirya', 'my-passwd');
mysql_select_db('test');
mysql_query('CREATE TABLE a (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE = InnoDB');
mysql_query('CREATE TABLE b (b INT AUTO_INCREMENT PRIMARY KEY, a INT NOT NULL, FOREIGN KEY (a) REFERENCES a(a) ON DELETE REST
mysql_query('INSERT a VALUES (1), (2), (3)');
$rs = mysql_query('SELECT a FROM a');
while ($row = mysql_fetch_assoc($rs)) {
        if (mysql_error()) die('Shouldn\'t happen: '.mysql_error());
        mysql_query('INSERT b (a) VALUES (4)');
        if (mysql_error()) echo "Foreign key constraint fails\n";
}
echo "Finished w/o errors\n";

Expected result:
----------------
Foreign key constraint fails
Finished w/o errors

Actual result:
--------------
Foreign key constraint fails
Shouldn't happen: Cannot add or update a child row: a foreign key constraint fails (`test/b`, CONSTRAINT `b_ibfk_1` FOREIGN KEY (`a`) REFERENCES `a` (`a`))

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-16 23:20 UTC] tony2001@php.net
Can't replicate.
Please provide reproduce code that really works.
 [2006-08-17 09:09 UTC] mirya at matrix dot ua
I recently found it being mentioned in mysql C API docs (for mysql_fetch_row()), IMHO there should be a note in PHP docs too.

2 tony2001@php.net: ensure you have mysql5 and no test.a, test.b tables ;)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 19:01:37 2025 UTC