Can't connect to MySQL via PHP
| From: | Rick Dwyer | Date: | Sat, 12 Jan 2013 16:25:58 +0000 |
| Subject: | Can't connect to MySQL via PHP | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-320066@lists.php.net to get a copy of this message | ||
Hello all.
I used the code below successfully to connect to a MySQL db on one hosting provider. I've
moved the code to a new hosting provider with new values and it returns:
Access denied for user 'user'@'db.hostprovider.net' (using password: YES)
Even though I can copy and paste these three values (host, user and pass) and paste into Navicat to
make a connection. So the credentials are correct, but they are not authenticating when used in
PHP. I've tried making host "localhost" and "127.0.0.1"… both with the
same result.
Can someone tell me what I am doing wrong here?
Appreciate it.
Thanks,
--Rick
$db_name = "mydb";
$vc_host = "db.hostprovider.net";
$vc_user = "user";
$vc_pass = "pass";
$connection = @mysql_connect($vc_host, $vc_user, $vc_pass);
$db = mysql_select_db($db_name, $connection);
echo mysql_error();