| Janwillem Borleffs 2004-05-18, 4:31 pm |
| jaquito13 wrote:
> I am working on a script that connects to MySQL databases using a
> function. To initiate the function in the example below, I would type
> the code --------
> dbconnect('main').
> --------I then want it to parse the user, host, and password into the
> function from preset variables. I think that you get the picture.
>
You probably searching for something like:
$user = 'user';
$pass = 'pass';
function connect($database) {
// Import the $user and $pass variables into
// the function's namespace to use it there
global $user, $pass;
....
}
But it will make the function more flexible when you pass the credentials as
arguments.
Also, don't forget to either return the resource or store it in a global
variable.
> $dbconnect = mysql_pconnect(eval(" $host =
> "$host ";"),
Why are you using eval when you don't need to:
$dbconnect = mysql_pconnect($host = 'host', $user='user', $pass='pass');
* or *
$host = 'host';
$user = 'user';
$pass = 'pass';
$dbconnect = mysql_pconnect($host, $user, $pass);
JW
|