constants help
Posted: Sun Aug 08, 2010 7:38 pm
Hello all, I am a new poster so thanks for any help. I am having a problem with figuring out how to reference data in a config file to a database connect class. I know many of you have probably seen this a hundred times, but I am having trouble sifting through all the nonsense on the net and finding a simple example.
Here is database.php:
Here is config.php:
So my question is basic, how do I get by database class to pull the info from config? To any volunteers, thanks for taking the time to help a new guy.
Here is database.php:
Code: Select all
<?php
include("config.php");
class database {
var $conn;
function __construct()
{
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
$db_selected = mysql_select_db($dbname);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
if (!$db_selected) {
die ("Can\'t use database : " . mysql_error());
}else {
echo 'Database connected sucessfully';
}
}
function insert()
{
mysql_query("INSERT INTO users (user_name, first_name)
VALUES ('bob', 'johnson')");
}
}
?>Code: Select all
define("dbhost", "localhost");
define("dbuser", "");
define("dbpass", "");
define("dbname", "");