Database Connect within WordPress
-
I created a Page called editSubscriber and created a custom Theme for it, so that I could embed php/html within the body. I want to run an SQL query from this page and echo the results to the page with php, but I cannot get my database to connect. I can get it to connect from my root folder but when I place the connection code at the top of Template for editSubscriber (in my theme folder) it says the table in the database does not connect. The exact error is:
QUERY ERROR:
SELECT cm_lastname, cm_status FROM subscriber_data WHERE cm_lastname = Wilson
Table ‘cmwordpress.subscriber_data’ doesn’t existFirst off, exactly where does the ‘cmwordpress’ come from? That is not the name of my database, or anything else that I can find.
Second, how can I get my database to connect? Like I said, i created a seperate script and placed it in my root folder (root wordpress not my theme) and it connected, and i am assuming it is just a file path issue, but how do I go about this? I was under the impression that when the theme files were read into the main index file, that it would look for a database from the root, but this isn;t the case. Any help here?
here is my db code:
<?php /* Template Name: pt_editsubscriber */ ?> <? // Makes initial conection to database define ('DB_USER', 'dbuser'); define ('DB_PASSWORD', 'password'); define ('DB_HOST', 'localhost'); 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.'); // Selects data from database $getsubscriber = "SELECT cm_lastname, cm_status FROM subscriber_data WHERE cm_lastname = Wilson"; $getsubscriber_result= mysql_query($getsubscriber) OR die('QUERY ERROR:<br />' .$getsubscriber. '<br />' .mysql_error()); ?> blah blah blah html code here <? while ($row = mysql_fetch_array($getsubscriber_result)) { $cm_firstname = $row["cm_firstname"]; $cm_status = $row["cm_status"]; echo" $cm_firstname<br/> $cm_status<br/> "; } ?>
- The topic ‘Database Connect within WordPress’ is closed to new replies.