so this is my code to connect to my database, when i am testing on my computer i use XAMPP fo开发者_Go百科r mac to test and everything were working fine til now. Im getting this when im trying to connect :
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'xxxxxxxxxxxxxxxxxxxxxxx' (4) in /Applications/XAMPP/xamppfiles/htdocs/lesite/functions.php on line 9
cannot connect
Now when i upload the website on my godaddy server it works like a charm!...
This is the code :
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
function loggedin()
{
if (isset($_SESSION['username'])||isset($_COOKIE['username']))
{
$loggedin = TRUE;
return $loggedin;
}
}
Please help me , thanks
Your MySQL server is not configured to allow connections from outside itself, only locally.
Further, you likely haven't set up a user for the purpose: users in MySQL are set-up on a per-host basis, so you'd have to explicitly create a yourname@%
or yourname@yourhost
in order to login remotely.
Well for one thing, try outputting the error on 'cannot connect':
mysql_connect("$host", "$username", "$password")
or die("cannot connect: ".mysql_error());
Also GoDaddy might have issues connecting to the mysql server when you are not on their domain, you have to check with them
You have your local MySQL server offline or you changed the $host value to something that is not true. Perhaps you introduced the $host variable somewhere in your script that is meant not to have anything in common with the database configuration.
By the way - the double quotes around your variables are not necessary. You can write:
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");
what type of hosting with GoDaddy do you have? I ran into the same problem with them, I needed to go into the database admin and select the database i was working on. before you go into phpadmin, edit the settings and enable remote access and then save the settings.
You also might need to follow Tomalaks post about setting up a user to access the db when not on the localhost.
I could be wrong but you might need to have linux hosting for that setting to be available, good luck!
精彩评论