Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix broken Events Manager database
<?php
$debug = true; //flip this switch if you're sure what you're doing
$configuration = parse_ini_file("config.ini", true);
// ** MySQL settings - You can get this info from your web host ** //
$db_configuration = $configuration['database'];
/** The name of the database for WordPress */
define('DB_NAME', $db_configuration['name']);
/** MySQL database username */
define('DB_USER', $db_configuration['user']);
/** MySQL database password */
define('DB_PASSWORD', $db_configuration['password']);
/** MySQL hostname */
define('DB_HOST', $db_configuration['host']);
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', $db_configuration['charset']);
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', $db_configuration['collate']);
$table_prefix = 'wp_';
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
/* Get all blog IDs */
$query = "SELECT blog_id FROM " . $table_prefix . "blogs";
$result = $db->query( $query );
while( $row = $result->fetch_object() ) {
$query_table_version = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $table_prefix . $row->blog_id . "_em_events' AND COLUMN_NAME = 'event_parent'";
$result_table_version = $db->query($query_table_version);
if($result_table_version->num_rows == 0) {
$update = "ALTER TABLE " . $table_prefix . $row->blog_id . "_em_events
ADD COLUMN event_parent bigint(20) unsigned NULL,
ADD COLUMN event_language varchar(14) NULL,
ADD COLUMN event_translation tinyint(1) unsigned NOT NULL DEFAULT 0,
MODIFY recurrence tinyint(1) unsigned NULL DEFAULT 0,
MODIFY event_private tinyint(1) unsigned NOT NULL DEFAULT 0,
MODIFY event_rsvp tinyint(1) unsigned NOT NULL DEFAULT 0,
MODIFY event_all_day tinyint(1) unsigned,
MODIFY event_status tinyint(1) unsigned";
if($debug)
var_dump( $update );
else {
var_dump( $update );
$res_update = $db->query( $update );
var_dump($db->error);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.