Page 1 of 1

NEWB: Easy database connection variable question

Posted: Fri Jun 19, 2009 7:27 pm
by splat78423
Here's the code....

<?php // db.php

$dbhost = "localhost";
$dbuser = "user";
$dbpass = "password";

function dbConnect($db="law") {
global $dbhost, $dbuser, $dbpass;

$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
or die("The site database appears to be down.");

if ($db!="" and !@mysql_select_db($db))
die("The site database is unavailable.");

return $dbcnx;
}
?>

The instructions say :
The function begins by connecting to the MySQL server using the $dbhost, $dbuser, and $dbpass variables at the top of the file (you'll need to set these to appropriate values for your server), and then if a database name was given it selects that database.

My question is, do I replace the global variable names listed on the line below with the actaul hostname, user, and password, do I put a $ before the actaul hostname, etc?
$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)

Thanks in advance

Re: NEWB: Easy database connection variable question

Posted: Sat Jun 20, 2009 5:46 am
by terier
just write your actual hostname,user,password in the first lines, where you assign the value to the variables.