Alright, I'm just in the early process of learning PHP, so forgive what is like a newbie mistake. I've written a config file defining these variables: <?php // MYSQL CONFIGURATION $mysqlServer = "localhost"; $mysqlUser = "user"; $mysqlPass = "password"; $mysqlDB = "database"; ?> And I'm calling them to connect to the database like this after including the config file: mysql_connect('$server', '$mysqlUser', '$mysqlPass') or die('I cannot connect to the database.'); mysql_select_db('$mysqlDB'); But of course on load it's looking for a host named '$server', etc. Why aren't the variables taking?
Don't enclose the variable names in single quotes. By doing that, you simply have the text '$server' instead of the value stored in the variable. mysql_connect ($server, $user, $passwd);
That removed the initial error but now I'm getting: Access denied for user 'nobody'@'localhost' (using password: NO) The database settings are definitely right, the script doesn't seem to be getting the user value from the variable (although it did get the server?). Any other ideas? Thanks for the help by the way!
I might be completly wrong, but this works for me In my config file I have $conn = mysql_connect($host, $userName, $password); return $conn; Code (markup): Then in the file I want to connect to the data base I have. include "<config file>.php"; mysql_select_db($dbName); $result = mysql_query("your SQL statement"); Code (markup):
Try somthing like this: $mysqlServer = "localhost"; $mysqlUser = "user"; $mysqlPass = ""; $mysqlDB = "database"; In your local server, if you do not set any username or password, then you don't need to set them, just leave the password blank. And the username as you set. May be it will help you.