Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/class-wpdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -3951,7 +3951,7 @@ protected function get_table_from_query( $query ) {
* @since 3.5.0
*/
protected function load_col_info() {
if ( $this->col_info ) {
if ( $this->col_info || ! ( $this->result instanceof mysqli_result ) ) {
return;
}

Expand Down
32 changes: 32 additions & 0 deletions tests/phpunit/tests/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,38 @@ public function test_get_col_info() {
$this->assertSame( $wpdb->users, $wpdb->get_col_info( 'table', 0 ) );
}

/**
* @ticket 64130
*
* @dataProvider data_get_col_info_without_result_set
*
* @param string $query Query that does not produce a result set.
*/
Comment thread
AKSHAT2802 marked this conversation as resolved.
public function test_get_col_info_without_result_set( $query ) {
global $wpdb;

$suppress = $wpdb->suppress_errors( true );
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( sprintf( $query, $wpdb->options ) );
$wpdb->suppress_errors( $suppress );

$this->assertNull( $wpdb->get_col_info(), 'get_col_info() should return null.' );
$this->assertNull( $wpdb->col_info, 'The col_info property should be null.' );
}

/**
* Data provider.
*
* @return array<string, string[]>
*/
public static function data_get_col_info_without_result_set() {
return array(
'failed query' => array( 'SELECT ID FROM table_that_does_not_exist' ),
'update query' => array( "UPDATE %s SET option_value = option_value WHERE option_name = 'blogname'" ),
'set query' => array( 'SET @wp_test_64130 = 1' ),
);
}

public function test_query_and_delete() {
global $wpdb;
$rows = $wpdb->query( "INSERT INTO $wpdb->users (display_name) VALUES ('Walter Sobchak')" );
Expand Down
Loading