OK so I've recently moved to MAMP for a project using PHP and mySQL. I开发者_运维百科've set up the database and copied all the data but now the script doesn't work. I haven't changed the default username or password. Any ideas? Here's the code I'm using, it fails at connecting to the database.
<?php
$dbhost = "localhost";
$dbname = "test";
$dbuser = "root";
$dbpass = "root";
mysql_connect("$dbhost", "$dbuser", "$dbpass") or die (mysql_error());
mysql_select_db("$dbname") or die(mysql_error());
?>
Check what value php.ini has for the default mysql socket - MAMP creates one in /Applications/MAMP/tmp/mysql whereas the mysql default location is /tmp
精彩评论