#38475 [NEW]: mysql_error doesn't reset after mysql_* func call

From: Date: Wed, 16 Aug 2006 18:03:49 +0000
Subject: #38475 [NEW]: mysql_error doesn't reset after mysql_* func call
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-100872@lists.php.net to get a copy of this message
From:             mirya at matrix dot ua
Operating system: FreeBSD6.1
PHP version:      5.1.4
PHP Bug Type:     MySQL related
Bug description:  mysql_error doesn't reset after mysql_* func call

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))

-- 
Edit bug report at http://bugs.php.net/?id=38475&edit=1
-- 
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38475&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38475&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38475&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=38475&r=fixedcvs
Fixed in release:             http://bugs.php.net/fix.php?id=38475&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=38475&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=38475&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=38475&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=38475&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=38475&r=notwrong
Not enough info:              http://bugs.php.net/fix.php?id=38475&r=notenoughinfo
Submitted twice:              http://bugs.php.net/fix.php?id=38475&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=38475&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=38475&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=38475&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=38475&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=38475&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=38475&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=38475&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=38475&r=mysqlcfg


Thread (4 messages)

« previous php.bugs (#100872) next »