Make WordPress Core

Ticket #14273: maybe_create_table.2.diff

File maybe_create_table.2.diff, 1.2 KB (added by pento, 14 years ago)
  • wp-admin/install-helper.php

     
    5151 * @param string $create_ddl Create database table SQL.
    5252 * @return bool False on error, true if already exists or success.
    5353 */
    54 function maybe_create_table($table_name, $create_ddl) {
     54function maybe_create_table( $table_name, $create_ddl ) {
    5555        global $wpdb;
    56         foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
    57                 if ($table == $table_name) {
    58                         return true;
    59                 }
    60         }
    61         //didn't find it try to create it.
    62         $wpdb->query($create_ddl);
     56        $query = $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name );
     57        if ( strtolower( $wpdb->get_var( $query ) ) == strtolower( $table_name ) )
     58                return true;
     59
     60        // Didn't find it, so we need to try to create it.
     61        $wpdb->query( $create_ddl );
     62
    6363        // we cannot directly tell that whether this succeeded!
    64         foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
    65                 if ($table == $table_name) {
    66                         return true;
    67                 }
    68         }
    69         return false;
     64        return ( strtolower( $wpdb->get_var( $query ) ) == strtolower( $table_name ) );
    7065}
    7166endif;
    7267