Im using the following to access tables information from my Wordpress DB
require_once(ABSPATH . 'wp-config.php');
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysqli_select_db($conn, DB_NAME);
It works fine I'm able to connect and display the information. The trouble is when I try to do the same thing from a plugin within the Dashboard under tools, I get the following message:
Notice: Use of undefined constant ABSPATH - assumed 'ABSPATH' in C:\xampp\htdocs\wordpressexpensereport\wp-content\plugins\editdb\connection.php on line 2
Warning: require_once(ABSPATHwp-config.php): failed to open stream: No such file or directory in C:\xampp\htdocs\wordpressexpensereport\wp-content\plugins\editdb\connection.php on line 2
Fatal error: require_once(): Failed opening required 'ABSPATHwp-config.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\wordpressexpensereport\wp-content\plugins\editdb\connection.php on line 2
I have checked my wp config and I do have the following
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');
Is there something I am missing with my implementation?
Thanks
require_once(ABSPATH . 'wp-config.php');
? Could it be that it's too early in the process, and wp-config.php has not loaded yet?$wpdb
object will not work?