NEWB: Easy database connection variable question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
splat78423
Forum Newbie
Posts: 2
Joined: Mon Jun 15, 2009 1:19 pm

NEWB: Easy database connection variable question

Post 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
terier
Forum Newbie
Posts: 9
Joined: Sat Jun 20, 2009 4:58 am

Re: NEWB: Easy database connection variable question

Post by terier »

just write your actual hostname,user,password in the first lines, where you assign the value to the variables.
Post Reply