Page is a not externally linkable
LinusIT - 3:40 pm on Feb 12, 2013 (gmt 0)
Hi
I'm trying to figure out how to set/define the database connection based on a mysql select. At present it runs the check on each page load which there is no need for.
//My database connection goes here
//Host Name
$domain = $_SERVER['HTTP_HOST'];
//Customer Check
$sql1 = "SELECT * FROM customers WHERE cust_domain = '$domain'";
$result1 = mysql_query($sql1) or die(mysql_error());
$num_rows1 = mysql_num_rows($result1);
//Set Customer Database Values
if ($num_rows1 > 0) {
while($row1 = mysql_fetch_row($result1)) {
$id = $row1['0'];
$name = $row1['1'];
$domain = $row1['2'];
$db_ip = $row1['3'];
$db_name = $row1['4'];
$db_username = $row1['5'];
$db_password = $row1['6'];
}
$customer_exists = true;
}
mysql_close($connect);
//Customer Database Connection
if ($customer_exists = true) {
$hostname = $db_ip;
$database = $db_name;
$username = $db_username;
$password = $db_password;
$connect = mysql_connect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database, $connect);
}
As you can see it checks for if the customer exists each time. Can anyone help me change the above so once it has checked it sets the customer database connection and does not check if they exist again please.
I know I'm missing lots of error checking etc but I just wrote this, once working I will add error checking etc.
Thanks