コード例 #1
0
ファイル: gd_db_install.php プロジェクト: hewu/blogwp
 /**
  * Creates table based on the table install file
  *
  * @global object $wpdb Wordpress DB class
  * @global string $table_prefix Wordpress table prefix
  * @param string $path base path to folder where the install folder is located with trailing slash
  */
 function create_tables($path)
 {
     global $wpdb, $table_prefix;
     $path .= "install/tables";
     $files = gdDBInstallGDPT::scan_folder($path);
     $collation = gdDBInstallGDPT::get_collation();
     foreach ($files as $file) {
         $file_path = $path . "/" . $file;
         $table_name = $table_prefix . substr($file, 0, strlen($file) - 4);
         if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name) {
             $fc = file($file_path);
             $first = true;
             $sql = "";
             foreach ($fc as $f) {
                 if ($first) {
                     $sql .= sprintf($f, $table_prefix);
                     $first = false;
                 } else {
                     if (strpos($f, '%COLLATE%') !== false) {
                         $sql .= str_replace("%COLLATE%", $collation, $f);
                     } else {
                         $sql .= $f;
                     }
                 }
             }
             $wpdb->query($sql);
         }
     }
 }