mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 17:48:01 +01:00
701dbb4d61
It can still mess up if you run it twice :-( git-svn-id: http://svn.automattic.com/wordpress/trunk@236 1a063a9b-81f0-0310-95a4-ce76da25c4cd
76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?php
|
|
require_once('../wp-config.php');
|
|
|
|
/**
|
|
** maybe_create_table()
|
|
** Create db table if it doesn't exist.
|
|
** Returns: true if already exists or on successful completion
|
|
** false on error
|
|
*/
|
|
function maybe_create_table($table_name, $create_ddl) {
|
|
global $wpdb;
|
|
foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
|
|
if ($table == $table_name) {
|
|
return true;
|
|
}
|
|
}
|
|
//didn't find it try to create it.
|
|
$q = $wpdb->query($create_ddl);
|
|
// we cannot directly tell that whether this succeeded!
|
|
foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
|
|
if ($table == $table_name) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
** maybe_add_column()
|
|
** Add column to db table if it doesn't exist.
|
|
** Returns: true if already exists or on successful completion
|
|
** false on error
|
|
*/
|
|
function maybe_add_column($table_name, $column_name, $create_ddl) {
|
|
global $wpdb;
|
|
foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
|
|
if ($column == $column_name) {
|
|
return true;
|
|
}
|
|
}
|
|
//didn't find it try to create it.
|
|
$q = $wpdb->query($create_ddl);
|
|
// we cannot directly tell that whether this succeeded!
|
|
foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
|
|
if ($column == $column_name) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
/**
|
|
** maybe_drop_column()
|
|
** Drop column from db table if it exists.
|
|
** Returns: true if it doesn't already exist or on successful drop
|
|
** false on error
|
|
*/
|
|
function maybe_drop_column($table_name, $column_name, $drop_ddl) {
|
|
global $wpdb;
|
|
foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
|
|
if ($column == $column_name) {
|
|
//found it try to drop it.
|
|
$q = $wpdb->query($drop_ddl);
|
|
// we cannot directly tell that whether this succeeded!
|
|
foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
|
|
if ($column == $column_name) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// else didn't find it
|
|
return true;
|
|
}
|
|
?>
|