Articles of dbdelta

Unable to create new database table upon plugin activation using dbDelta

I’m trying to create a new database table when my plugin is activated using dbDelta() however, no new table seems to be creating. Since I’m new to WordPress development, please let me know where I’m going wrong. <?php /* Plugin Name: Xenon-Result Plugin URI: Description: Basic WordPress Plugin Header Comment Version: 1.0 Author: Himanshu […]

Is altering a default WordPress database table update safe?

I want to add some table columns to the wp_terms table. Is it safe to use the dbDelta function with a modified CREATE-MySQL query for this? Or will I run into problems in the long turn? Is it update safe? As a database rookie I hope someone with more experience can help me out here. […]

Create new database through static page code

I want to create a new table in current database of word press through create a static page. I write code for this as below, but there was no result. Why is that, and how can I get this right? <?php /* Template Name:Register Page Template URI: Author:yuva Author URI: Description:This Is Page for Gallery. […]

dbDelta not creating tables with composite keys

I’ve been trying to figure this one out for 3 days now, reading every reference on dbDelta I can find. My ultimate goal is to create a table of unique ad_id, ad_trigger pairs. This does not create a table: if($wpdb->get_var(“SHOW TABLES LIKE ‘$ad_trigger_table_name'”) != $ad_trigger_table_name) { $sql = “CREATE TABLE ” . $ad_trigger_table_name . ” […]

dbDelta() Error – Incorrect index name '' for query ALTER TABLE

The famous dbDelta() function in WordPress is causing me problems in multiple plugins. No change I make to my create table query seems to fix the problem or it does fix it and dbDelta() causes a different error after the change. Advice on these specific CREATE TABLE queries would be appreciated a lot. [21-Oct-2016 23:01:29 […]

dbDelta not installing database

I’m not sure why this isn’t running. When I output dbDelta it says that it created the table, but it doesn’t. I think my SQL is valid. Taking everything out between id and UNIQUE KEY results in the table being made, but I don’t see the problem with the other lines. Thanks function email_install () […]

Unable to set a default serialized array using dbdelta()

I am trying to set up a table with dbDelta() and one of the columns will have as default a serialized array with predefined values. The issue here is that dbDelta() explodes the query using semicolons to separate the queries. Is there any workaround for this? The charset I’m using for said column is utf8_bin. […]

Custom database table for plugin not creating on activation

Let me start by saying I know there are other posts about this, and a lot of documentation is available for this topic, but none of these resources have helped me to solve my issue. I’m a beginner at creating plugins for WordPress. This is my first, so I’m sure I’m missing something simple, but […]

How to update an existing table while updating plugin?

I have added a new field (time_last_seen) in my plugin (v1.1) table then uploaded my plugin as version 1.2 to wordpress svn repository. When I update my plugin from admin panel, it is not creating the field (time_last_seen) in the table. Here is what I have tried: function ulh_add_user_logins_table() { global $wpdb; $oldVersion = get_option( […]

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