Connecting to WordPress Database

I have a problem with my custom theme for wordpress. I made a custom theme locally on my PC where I installed WordPress. Now inside my theme is another folder let’s say php, and inside this folder is a php file that will fetch data from the database which I want to run later on. The code in this php file is as follows:

<?php
define('WP_USE_THEMES', false);
require('/wp-blog-header.php');
header('HTTP/1.1 200 OK');
global $wpdb;
$rs = $wpdb->get_results("select * from wp_users"); 
$user_db=$rs[0]->user_nicename;
echo $user_db;
?>

The codes above works on my local machine, where it prints out the user_nicename field from my local database (phpMyAdmin). Now when I upload and install the custom theme I made and access this php file the browser displays nothing. Is something missing in define or require so I can successfully connect to the WordPress database? Any help help would be much appreciated.
Please note that theme is located at C:wampwwwwordpresswp-contentthemescustom_theme and the php file to connect to database is here: C:wampwwwwordpresswp-contentthemescustom_themephpconnect.php

Related posts

Leave a Reply

1 comment