CREATE TABLE with dbDelta does not create table

Found a couple of things and am including what I believe will work to correct your issue. (As an aside, you should try and simplify your initial attempts so you can isolate what works and what doesn’t. This is really complex for an initial attempt.) One thing, you’ll struggle to have a field named timestamp, … Read more

Create new database through static page code

DBDelta is extremely picky— to the point of being maddening sometimes. From the Codex: You must put each field on its own line in your SQL statement. You must have two spaces between the words PRIMARY KEY and the definition of your primary key. You must use the key word KEY rather than its synonym … Read more

dbDelta not adding additional columns in plugin database update

After trial and error, here is the code that works: function installer(){ include(‘installer.php’); } register_activation_hook( __file__, ‘installer’ ); //executes installer php when installing plugin to create new database //database update checkdate function myplugin_update_db_check() { global $xenon_result_db_version; if ( get_option( ‘xenon_result_db_version’ ) != $xenon_result_db_version ) { installer(); } } add_action( ‘plugins_loaded’, ‘myplugin_update_db_check’ ); The installer.php looks … Read more

Why my query ‘REPLACE INTO…’ does not work?

The reason is due to this code inside dbDelta() : // Create a tablename index for an array ($cqueries) of queries. foreach ( $queries as $qry ) { if ( preg_match( ‘|CREATE TABLE ([^ ]*)|’, $qry, $matches ) ) { $cqueries[ trim( $matches[1], ‘`’ ) ] = $qry; $for_update[ $matches[1] ] = ‘Created table ‘ … Read more