So I'm having an issue connecting to a mySQL database I created on my local host using XAMPP. The DB itself is set up fine on 127.0.0.1, but I had to use port 8000 (instead of 80) to get it to start in XAMPP.
$con = mysql_connect("localhost:8000","","");
if (!$con) {
die('Connection failed.' . mysql_error());
}
The above doesn't work, the browser times out after a few seconds saying it cannot display the webpage (note that it doesn't give the die message). I have also tried 127.0.0.1:8000 but no luck. Creating a user in phpMyAdmin and entering the credentials didn't achieve anything either.
If I take out the port and just use:
$con = mysql_connect("localhost","","");
This connects, but I can't seem to select my database because I don't think it's connecting to the right server!
Any ideas? Thank you in advance!
mysql_*functions in new code. They are no longer maintained and the deprecation process has begun on it. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.