Saya telah melalui banyak utas, halaman codex dan mencoba mengacaukan banyak hal tetapi kode saya sepertinya tidak membuat tabel. Dan saya tidak bisa mencari tahu di mana saya salah. Saya memeriksa booking_db_version dalam database, ini akan diperbarui ketika saya memperbaruinya dalam file.
Ini kodenya
global $booking_db_version;
$booking_db_version = "1.0.0";
function booking_install() {
global $wpdb;
global $booking_db_version;
global $tableprefix;
$installed_version = get_option('booking_db_option');
$tableprefix = $wpdb->prefix . 'booking_';
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
if ( $installed_version !== $booking_db_version ) {
/* Create table for packages */
$packagetable = $tableprefix . 'packages';
$sql = "create table $packagetable (
id mediumint(9) NOT NULL AUTO_INCREMENT,
name text NOT NULL,
description text NOT NULL,
city1 text NOT NULL,
city2 text NOT NULL,
PRIMARY KEY (id)
);";
dbDelta($sql);
/* Create table for hotels */
$hoteltable = $tableprefix . 'hotels';
$sql = "create table $hoteltable (
id mediumint(9) NOT NULL AUTO_INCREMENT,
name text NOT NULL,
city text NOT NULL,
price decimal(10,2) NOT NULL,
PRIMARY KEY (id)
);";
dbDelta($sql);
/* Create table for addons */
$addontable = $tableprefix . 'addons';
$sql = "create table $addontable (
id mediumint(9) NOT NULL AUTO_INCREMENT,
name text NOT NULL,
addongroup text NOT NULL,
price decimal(10,2) NOT NULL,
PRIMARY KEY (id)
);";
dbDelta($sql);
/* Create table for addon groups */
$addongrouptable = $tableprefix . 'addon_groups';
$sql = "create table $addongrouptable (
id mediumint(9) NOT NULL AUTO_INCREMENT,
name text NOT NULL,
perhead text NOT NULL,
PRIMARY KEY (id)
);";
dbDelta($sql);
update_option('booking_db_version', $booking_db_version);
}
}
register_activation_hook(__FILE__, 'booking_install');
CREATE TABLE
akan menyebabkan kegagalan.