Can't Connect to MYSQL via PHP [closed]
I've tried connecting to mysql via my registered server on dreamhost, and via localhost. Neither one seems to work. I know I'm giving the proper data for user and such, but all I get is a dead connection.
I'm running Ubuntu 11.04...
edit
Ok, sorry for the lack of description. I have added my ip to the Dreamhost control panel. My code resembles th开发者_高级运维e following:
define('SERVER', 'mysql.hostname.com');
define('USERNAME', 'xxxxx');
define('PASSWORD', 'xxxxx');
$connection = mysql_connect(SERVER, USERNAME, PASSWORD) or die("error, cannot connect to mysql.");
when I do a var_dump() on the variable, all I get is a simple
bool(false)
Well, I'm not sure this strictly belongs here, and I'd really like more information about, say, the specific PHP code you're using to log in, but here are a few gotchas with Dreamhost, just in case they happen to match your particular issue:
- The mysql server is not
localhost
or your web server's domain. Instead, it's usuallymysql.mydomain.com
. Check your specific MySQL settings in the Dreamhost control panel. - If you try to connect from another computer, you will be rejected unless that IP address has specifically been added in the MySQL section of Dreamhost's control panel. I noted you tried via
localhost
, but note that, even if you're trying the right server as per suggestion #1, you'll still get bum results from your personal computer unless the IP is whitelisted.
For the one on dreamhost, unless you specify that connections can be accepted from your local ip, it will not work. Read up on Mysql Access Control here
As for localhost, it should connect, but you need to provide more information on what your setup is i.e. whether you are connecting through -hhostname or just connecting through a local socket. Also what do you mean by "dead connection".
精彩评论