[wp-trac] [WordPress Trac] #23085: Calling $wpdb->query() when no connection exists causes mysql_error() to throw an error
WordPress Trac
noreply at wordpress.org
Sun Dec 30 10:30:49 UTC 2012
#23085: Calling $wpdb->query() when no connection exists causes mysql_error() to
throw an error
------------------------------------+--------------------------
Reporter: mbijon | Type: defect (bug)
Status: new | Priority: normal
Milestone: Awaiting Review | Component: Database
Version: 3.5 | Severity: normal
Keywords: dev-feedback has-patch |
------------------------------------+--------------------------
In the query() method of wp-db.php, the mysql_error() expects that if a
parameter is passed to it then it should be a valid link identifier.
*May need feedback or added testing* ...this error may be specific to
transactions, which is why it hasn't been noticed before. Unit tests do
use transations and I only get these errors when ROLLBACK is called during
specific unit tests that don't modify the DB state. A simple transaction
opened & rolled back in the Debug Bar Console is not triggering this for
me.
Unit test failure examples:
'''Test: test_is_image_positive'''
{{{
mysql_error() expects parameter 1 to be resource, integer given
Execution time: 0.02507209777832s
Stack Trace:
Array
(
[0] => Array
(
[file] => C:\xampp\htdocs\wpnew\wp-includes\wp-db.php
[line] => 1202
[function] => mysql_error
[args] => Array
(
[0] => 0
)
)
[1] => Array
(
[file] => C:\xampp\htdocs\wp_test_svn\includes\testcase.php
[line] => 25
[function] => query
[class] => wpdb
[type] => ->
[args] => Array
(
[0] => ROLLBACK
)
)
)
}}}
'''Test: test_is_image_negative'''
{{{
mysql_error() expects parameter 1 to be resource, integer given
Execution time: 0.02237606048584s
Stack Trace:
Array
(
[0] => Array
(
[file] => C:\xampp\htdocs\wpnew\wp-includes\wp-db.php
[line] => 1202
[function] => mysql_error
[args] => Array
(
[0] => 0
)
)
[1] => Array
(
[file] => C:\xampp\htdocs\wp_test_svn\includes\testcase.php
[line] => 25
[function] => query
[class] => wpdb
[type] => ->
[args] => Array
(
[0] => ROLLBACK
)
)
)
}}}
I don't think we should attempt {{{if ( $this->last_error = mysql_error()
)}}}. That is because when mysql_error() is called without a link
identifier then the most recent connection to MySQL is referenced. On a
busy server this may not be the same connection as our page or transaction
originally used. See #3544 for history/details.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23085>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list