Articles of dbdelta

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 […]

dbDelta ALTER TABLE syntax?

Due to some changes in the DB, I need to alter a table to add one column to it, but even though the function is running, the table isn’t altered. Here’s the ALTER TABLE code that I’ve written $sql = “ALTER TABLE ” . $packagetable . ” ADD COLUMN price decimal(14,2) NOT NULL AFTER description;”; […]

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 […]

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: // […]

What files to keep after upgrading WordPress?

We were recently handed a few blogs/sites to support, that have started way back when wordpress was on v2.1.3 or even 2.0.4 After upgrading the sites to the latest versions (3.4.2 and 3.5) we found that there are files in the root directory as well as the /admin and /includes that are “leftovers” from the […]

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 […]

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) […]

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) […]

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 […]

Does dbDelta delete columns as well?

I created a table using the dbDelta function and then removed a few columns and added a few. The new columns did get created but the old columns did not get deleted from the table. Is there a different way I am supposed to delete columns from the table ?