Mysql DB connection issues

Soldato
Joined
27 Dec 2005
Posts
17,296
Location
Bristol
I've finished a site using XAMPP and it all works fine, but upon uploading to the server it doesn't seem to like the way I'm connecting to the database.

Code:
$dbHost = "localhost";
$dbUser = "user";
$dbPass = "password";
$dbName = "name";

$mysqli = new mysqli($dbHost, $dbUser, $dbPass, $dbName);

if(!$mysqli) {
echo "Could not connect to server";
exit;
}
if(!mysql_select_db($dbName)) {
echo "Could not select database";
exit;
}

On my local machine this works fine, but on the server I get the following errors:

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'root'@'localhost' (using password: NO) in /home/etc/index.php on line 17

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/etc/index.php on line 17
Could not select database

It's not a username/password issue as I can't connect to an old database either. However using a previous connection method - $link = mysql_connect($dbHost, $dbUser, $dbPass); - does work, but then my code later on doesn't work due to the different method.

Any ideas?
 
Last edited:
Soldato
OP
Joined
27 Dec 2005
Posts
17,296
Location
Bristol
Urgh, fixed. I don't know what the deal is but I don't think mysqli accepts variables on my server? I put the values of all the variables straight into the mysqli function and it works fine.
 
Back
Top Bottom