I’ve created a database on my 1&1 server, I can connect to it through the Plesk control panel with the user I created. I’ve even “reset” the user password to the one I have in my script and can still connect through WebAdmin. However, my PHP script keeps returning the Unable to connect error. I’ve looked over this code time and again and can’t see what it is I am missing. Hopefully someone can show me the error of my ways
// Database connection string
require_once(‘inc_dblogin.inc’);
$db_server = mysqli_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to MySQL: " . mysqli_error());
mysqli_select_db($db_database)
or die("Unable to select database: " . mysqli_error());
The inc_dblogin.inc file just contains the values for my connection, which I’ve also echoed to the screen from this file to make sure they are properly being chosen and they are good. I’m at a loss as to what it is I am doing wrong. Any suggestions would be greatly appreciated.
Greg
That’s one of the things I don’t get, it doesn’t show any error code, just simply my notice - "Unable to connect to MySQL: " (without the quotes, but no error code follows it.
Greg
to the top of the script I was currently working on and it would then display (access denied for user blahblahblah) which then pointed me in the direction to look instead of just guessing.
All stuff I should remember from all the books I’ve read that have told me that over and over, but now that I am actually working on a real world app, maybe it will finally start to sink in.
Thanks guys! Hope this helps someone else down the line.