ginginca wrote:I have spent hours and can't figure this out:
$database['host']="localhost";
$database['name']="whatever the database name is";
$database['pass']="whatever the password is";
$database['user']="whatever the user is";
//DATABASE CONNECTION
$sql_conn = mysql_connect($database[host], $database[name], $database[pass], $database[user]);
if (!$sql_conn)
{
die('Could not connect: ' . mysql_error());
}
I have re-typed and rechecked for over an hour. And I'm still getting an error that I'm not connecting to the database.
Would one of you fine gurus tell me what you figure I am doing wrong? I have re-set the permissions twice and even tried a different user with global privileges. I am hoping it's something in the code ... 'cause this is driving me nuts!
Many thanks!
First, you need to have established a mySQL accessable database on some host server.
Then, you have to call the mysql _connect function (e.g. mysql_connect('website', 'id', 'password') with the appropriate arguments to initially connect to the database with your host url, userid, and password).
When that has been completed successfully, you need to use the mysql_select_db function to select the database you need to use on that connection (e.g. mysql_select_db(Mydatabase).
The code you have presented describes an array in PHP which contains your database conection parameters, but still requires an established database on your server.
Are you sure that you database has been created with the parameters you specified in the $database array variable name?
Also, the syntax
../[code=php] you use in your example is not standard to the usual html tags of <?php>..</php> or other shortcuts.