mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
wpdb::flush() was not flushing results correctly when using mysqli.
This change also allows stored procedures or queries made with `mysqli_multi_query()` to be flushed. Includes unit tests. Fixes #28155. Props soulseekah. git-svn-id: https://develop.svn.wordpress.org/trunk@30297 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c8340a2cda
commit
4b1aa89206
@ -1322,12 +1322,16 @@ class wpdb {
|
||||
$this->rows_affected = $this->num_rows = 0;
|
||||
$this->last_error = '';
|
||||
|
||||
if ( is_resource( $this->result ) ) {
|
||||
if ( $this->use_mysqli ) {
|
||||
mysqli_free_result( $this->result );
|
||||
} else {
|
||||
mysql_free_result( $this->result );
|
||||
if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
|
||||
mysqli_free_result( $this->result );
|
||||
$this->result = null;
|
||||
|
||||
// Clear out any results from a multi-query
|
||||
while ( mysqli_more_results( $this->dbh ) ) {
|
||||
mysqli_next_result( $this->dbh );
|
||||
}
|
||||
} else if ( is_resource( $this->result ) ) {
|
||||
mysql_free_result( $this->result );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -458,4 +458,36 @@ class Tests_DB extends WP_UnitTestCase {
|
||||
$this->assertEquals( $expected2, $wpdb->last_query );
|
||||
$wpdb->suppress_errors( $suppress );
|
||||
}
|
||||
|
||||
/**
|
||||
* mysqli_ incorrect flush and further sync issues.
|
||||
*
|
||||
* @ticket 28155
|
||||
*/
|
||||
function test_mysqli_flush_sync() {
|
||||
global $wpdb;
|
||||
if ( ! $wpdb->use_mysqli ) {
|
||||
$this->markTestSkipped( 'mysqli not being used' );
|
||||
}
|
||||
|
||||
$suppress = $wpdb->suppress_errors( true );
|
||||
|
||||
$wpdb->query( 'DROP PROCEDURE IF EXISTS `test_mysqli_flush_sync_procedure`' );
|
||||
$wpdb->query( 'CREATE PROCEDURE `test_mysqli_flush_sync_procedure`() BEGIN
|
||||
SELECT ID FROM `' . $wpdb->posts . '` LIMIT 1;
|
||||
END' );
|
||||
|
||||
if ( count( $wpdb->get_results( 'SHOW CREATE PROCEDURE `test_mysqli_flush_sync_procedure`' ) ) < 1 ) {
|
||||
$wpdb->suppress_errors( $suppress );
|
||||
$this->markTestSkipped( 'procedure could not be created (missing privileges?)' );
|
||||
}
|
||||
|
||||
$this->factory->post->create();
|
||||
|
||||
$this->assertNotEmpty( $wpdb->get_results( 'CALL `test_mysqli_flush_sync_procedure`' ) );
|
||||
$this->assertNotEmpty( $wpdb->get_results( "SELECT ID FROM `{$wpdb->posts}` LIMIT 1" ) );
|
||||
|
||||
$wpdb->query( 'DROP PROCEDURE IF EXISTS `test_mysqli_flush_sync_procedure`' );
|
||||
$wpdb->suppress_errors( $suppress );
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user