Skip to content

Commit e401ef1

Browse files
authored
Require DB_NAME to be set only in the new driver (#197)
Require `DB_NAME` to be set only in the new driver. As reported in #194 (comment): > I have this plugin on a site, and the Plugins admin page offered me the upgrade. I upgraded, and it broke the site, due to previously I did not have define( 'DB_NAME', '...' ); in wp-config.php. The error message was: > Error: Undefined constant "DB_NAME" in .../wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/db.php on line 69
2 parents 6fc6ad0 + 0332e61 commit e401ef1

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

wp-includes/sqlite/class-wp-sqlite-db.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ public function db_connect( $allow_bail = true ) {
307307
$pdo = $GLOBALS['@pdo'];
308308
}
309309
if ( defined( 'WP_SQLITE_AST_DRIVER' ) && WP_SQLITE_AST_DRIVER ) {
310+
if ( null === $this->dbname || '' === $this->dbname ) {
311+
$this->bail(
312+
'The database name was not set. The SQLite driver requires a database name to be set to emulate MySQL information schema tables.',
313+
'db_connect_fail'
314+
);
315+
return false;
316+
}
317+
310318
require_once __DIR__ . '/../../wp-includes/parser/class-wp-parser-grammar.php';
311319
require_once __DIR__ . '/../../wp-includes/parser/class-wp-parser.php';
312320
require_once __DIR__ . '/../../wp-includes/parser/class-wp-parser-node.php';

wp-includes/sqlite/db.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@
6666
require_once $crosscheck_tests_file_path;
6767
$GLOBALS['wpdb'] = new WP_SQLite_Crosscheck_DB( DB_NAME );
6868
} else {
69-
$GLOBALS['wpdb'] = new WP_SQLite_DB( DB_NAME );
69+
$GLOBALS['wpdb'] = new WP_SQLite_DB( defined( 'DB_NAME' ) ? DB_NAME : '' );
7070
}

0 commit comments

Comments
 (0)