Problem in creating table through plugin code

I’m using the following code to create the database table using plugin. However, the table is neither getting created nor I’m getting any error message. The code is as follows: global $wpdb; $table_name = “tbllb_club”; $sql = “create table $table_name ( club_id int(11) NOT NULL auto_increment, project_name varchar(500) NOT NULL, first_name varchar(100) NOT NULL, school_status … Read more

Why does dbDelta() not catch MysqlErrors?

From what I can see, dbDelta() is designed to suppress database errors that occur during its operation. Generally speaking, this seems to be the case, but New Relic is still reporting MysqlErrors from the function. The exact error message is of the format: MysqlError: Table ‘xxx.wp_yyy_posts’ doesn’t exist From dbDelta() in /wp-admin/includes/upgrade.php, we have: // … Read more

Fatal error: Call to undefined function dbDelta()

I want to create a table during the activation of the plugin, so I used the code as follows: class Database { private $db_version = ‘1.0’, $table_prefix; public function __construct() { global $wpdb; $this->table_prefix = $wpdb->prefix; register_activation_hook( PLUGIN_INDEX_FILE, array($this, ‘dbSetup’) ); } public function dbSetup() { $countriesSQL = “CREATE TABLE $this->table_prefix . countries ( id … Read more

Problems with DBDelta with FOREIGN key?

I have the following sql I am using with dbDelta: $sql .= “CREATE TABLE ” . $location_table . ” ( location_id MEDIUMINT(9) NOT NULL AUTO_INCREMENT, name VARCHAR (100), street_no VARCHAR (5), street_name VARCHAR (75), city VARCHAR (75), province_state VARCHAR (75), postal_code VARCHAR(10), country VARCHAR (75), post_page_url VARCHAR(300), icon_id MEDIUMINT(9), PRIMARY KEY (location_id), FOREIGN KEY (icon_id) … Read more

dbDelta does not create Table, but returns success

I wrote a Plugin, which creates a table on activation. On previous WP Versions, it worked fine. Now it doesn’t. This is my function: function on_activation(){ global $wpdb; $table_name = $wpdb->prefix.”tc_competition_data_all_countries_and_fields”; $sql = “CREATE TABLE $table_name ( mail VARCHAR(55), id VARCHAR(255) NOT NULL, time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, name VARCHAR(255) NOT NULL, stra VARCHAR(255) … Read more

How to define composite keys with dbDelta()

I am getting error while trying to create a table with dbDelta() and composite primary key. The sql is pretty straight forward. $sql = “CREATE TABLE {$wpdb->prefix}voicemail_call ( user_id BIGINT(9) UNSIGNED NOT NULL, call_id BIGINT(9) UNSIGNED NOT NULL, opened BOOL DEFAULT 0 NOT NULL, PRIMARY KEY (user_id, call_id) );”; dbDelta($sql); This shows error WordPress database … Read more

dbDelta only creates the last table

I’m using following install function with dbDelta as referring to the codex, articles on SO I watched out for the typical problems with e.g. one space instead of two spaced at the PRIMARY KEY … function myplugin_install(){ global $wpdb; $table_name = $wpdb->prefix . “vehicles”; $sql = “CREATE TABLE IF NOT EXISTS $table_name ( id INT … Read more