0

I am trying to migrate from MySQLi to PDO (PHP 5.5.20, MySQL v5.0.11, Fedora 19) to no avail:PDO simply refuses to make a connection, and I have checked everywhere for an answer. My code is as simple this:

ini_set('display_errors', 1);
error_reporting(E_ALL);
$hostname_localhost ="127.0.0.1";
$database_localhost ="ilinfra_administration";
$username_localhost ="ilinfra_euldlm58";
$password_localhost ="nhmtqvuhdldlea1999";
$userID    = 106;
$rel1LegID = "V13310604";
$dsn = 'mysql:dbname=ilinfra_administration;host=localhost;port=3306';
try{
   $dbh = new PDO($dsn,$username_localhost,$password_localhost);
}
catch(PDOException $e)
{
    echo $e->getMessage();
}
exit();

The flow goes past the try block, no IDE screaming, no errors displayed, no PDO object created. localhost and 127.0.0.1 fail. Adding or removing a database port both fail. The wrong password will throw an exception (no user access), not the database name or the username. That's where everything starts to complain. I will appreciate your help an awful lot.

  • 2
    there are no errors because you didn't query anything yet. – Ibu Oct 07 '15 at 21:41
  • What does the complaining look like and what is the query being used when complaints are heard? – chris85 Oct 07 '15 at 21:43
  • I think you should take a look at [these examples](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers#Running_Simple_Select_Statements) which are very simple and might help you through the process. just as @lbu say's you didn't query anything. I'm pretty sure that if you do a `print_r($dbh)` it will output the PDO object – mloureiro Oct 07 '15 at 21:49
  • The only complaint is "SQLSTATE[HY000] [1045] Access denied for user 'ilinfra_euldlm58'@'localhost' (using password: YES)" In short, no matter how crazily I change parameters I only get a response when I type an inexistent password. Both Eclipse and PHPStorm do not show a connection being opened. Same whole situation on my hosting server. – PepinhoDoSamba Oct 07 '15 at 22:13
  • You do not need to query in order to get an error. When you open a connection a memory structure is created that holds a lot of data about the connection. If the connection failed there is no way you can query. In other words: you don't know if the door opens until you unlock it first. Also, print_r() showed nothing. – PepinhoDoSamba Oct 07 '15 at 22:18
  • First, var_dump() showed there was an object, but no details about it. Next, the page provided by Pedro Lobito had the solution: don't expect anything from "new PDO" because you do have to query before knowing if you have a connection or not (just as absurd as buying the tires before you buy the car, and a first for me after 30 years programming) Thanks to everyone, but the answer is Pedro's. Lastly, how do I upvote here? I am a newbie to SO. – PepinhoDoSamba Oct 07 '15 at 22:55
  • Have you tried it with the correct username and password? – Ibu Oct 08 '15 at 05:10
  • Problem solved, guys. Thank you very much, if three years late. – PepinhoDoSamba Feb 16 '19 at 13:59

0 Answers0