Problem to connect on MySql database on the remote server
I have been developing my php mysql application locally and it worked fine with this connection parameters:
// Database connection params
define('HOST', 'localhost');
define('USERNAME', 'root');
define('PASSWORD', '');
define('DATABASE', 'some_db');
at some point I wanted to put application online with connection parameters:
define('HOST', 'somedomain.com');
define('USERNAME', 'some_db_admin');
define('PASSWORD', 'Password1!');
define('DATABASE', 'some_db');
When I try to connect to remote database like this:
function db_connect()
{
$connection = @mysql_connect(HOST, USERNAME, PASSWORD);
if(!$connection)
{
return false;
}
if(!mysql_select_db(DATABASE))
{
return false;
}
return $connection;
}
I get error: Acc开发者_如何学Cess denied for user 'some_db'@'localhost' (using password: NO)
How can it possibly be localhost?
I have regularly created database and user that database using using database wizard in cpanel.
What can be the problem?
Thanks a lot!
If your PHP code is at the same host where the MySQL database is then setting HOST to localhost should solve your problem
define('HOST', 'localhost');
It also seems that you swapped your constants, because some_db is not likely to be a user but rather a database. Try debugging and output the constants' values just before the 'mysql_connect' call. If this does not work, try debug_backtrace().
精彩评论