Database Connection in WordPress
-
I created a Page called editSubscriber, and then created a custom Template for this page so that I could run php/html code within the body. That works fine. The idea is to connect to my database (not my wordpress database but another database on the same server) and SELECT data from it, display it on the page and allow the user to edit the data. This is an internal intranet type page that will be passworded so don’t freak out.
Anyhow, when i try to connect to this other database from my Template page, it gives me an error that the table I am seeking does not exist. It is doing this because it is looking in the wordpress database and not the other one. My connection code specifically tells it which database to look in, but for some reason it keeps redirecting back to the wordpress database, dos anyone know how to avert this?
When I run the script from the root wordpress directory it works fine. If I run it from my themes folder, it looks at the wrong database.
My connection code:
<?php // Makes initial conection to database define ('DB_USER', 'username'); define ('DB_PASSWORD', '********'); define ('DB_HOST', 'mysql15.myserver.com'); define ('DB_NAME', 'cmsubsdata'); $connect = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Our database is currently down for updates, please check back later.'); $db = @mysql_select_db(DB_NAME, $connect) or die('Our database is currently down for updates, please check back later.'); ?>
- The topic ‘Database Connection in WordPress’ is closed to new replies.