unknown mysql server host (11001)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jan_sc
Forum Newbie
Posts: 8
Joined: Wed Aug 01, 2007 3:10 am

unknown mysql server host (11001)

Post 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");
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply