I give you something interesting here since I researched all stackoverflow but nobody had ever asked for a similar issue! Let's go with the description:
I'm trying to connect a simple mysql database to my server using php. I can say from now that the issue is present with both the PDO and the mysql_connect methods. Now I'll explain to You:
In the typical "TRY-CATCH" block I want to test the Error Message for some exceptions. So I did something like the following:
try {
$db = new PDO("mysql:host=localhost;dbname=shirts4mike;","root","ffredda");
$db -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db -> exec("SET NAMES 'utf8'");
} catch (Exception $e) {
echo "Could not connect to the database.";
exit;
}
Now, to test the error message, I tried to change the host to:
host=Wronghost;
and refreshed the page running on a local server (apache2).
And here we go with the problem! It takes something like two minutes before my browser catches the exception and loads the error message.
I'm becoming crazy with this! I don't know on what it depend! I think it's the server trying multiple times to connect to the database before giving up and throw the Exception! But how to limit this number of attempts if this is the problem? And if this isn't the problem someone has an idea about where to look to find and solve it? Who is the responsible? Mysql? Apache? The PHP code (which I doubt)?
I would really appreciate any help. Really. Thank You anwyway and hope to hear from someone soon!
--Fabrizio