Page 1 of 1

unknown mysql server host (11001)

Posted: Wed Aug 01, 2007 5:08 am
by jan_sc
hello,

i'm new to php and i'm currently working with some php codes. i'm trying to make a connection to mysql with the codes below but was given an error "Unknown MySQL server host 'DB_HOST' (11001)". if i replace $rst with "$rst = @mysql_connect("11.22.333.44", "username", "password");", it works fine. any help will be much appreciated. tia

Code: Select all

<?
include_once("conf/include.conf");

$rst = @mysql_connect(DB_HOST, DB_UID, DB_PASSWD);

if (!$rst){
	 echo( "<p>Unable to connect to database manager.</p>");
       die('Could not connect: ' . mysql_error());
	 exit();
} else {
  echo("<p>Successfully Connected to MySQL Database Manager!</p>");
}

if (! @mysql_select_db(DB_DATABASE) ){
	 echo( "<p>Unable to  connect database...</p>");
	 exit();
} else {
  echo("<p>Successfully Connected to Database 'Production'!</p>");
}
?>
//include.conf

Code: Select all

<?
session_start();
include_once("db.conf");
?>
//db.conf

Code: Select all

<?
define("DB_HOST", "11.22.333.44");
define("DB_UID", "username");
define("DB_PASSWD", "password");
define("DB_DATABASE", "test");
?>

Posted: Wed Aug 01, 2007 6:50 am
by feyd
db.conf probably did not load. You shouldn't leave your connection details in the open. .conf is not normally processed by php; if someone requests db.conf they will be able to see your connection information.

Also, since you are new to PHP, here's a few things: "<?" (and "<?=") shouldn't be used. Opt for "<?php" instead. Using constants for your database connection information is almost as bad as leaving them in the open. This is due to the inability to destroy constants. It is suggested to use variables (at most) which you can unset() after use.