|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-08-16 23:20 UTC] tony2001@php.net
[2006-08-17 05:46 UTC] georg@php.net
[2006-08-17 09:09 UTC] mirya at matrix dot ua
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 08:00:02 2025 UTC |
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`))