After a long time using mysql I finally decided to migrate everything to PDO as the prior is being depreciated.
I began by looking into some tutorials on using PDO, and right from the start I am having problems…
I am running:
Apache (v2.2.22)
MySQL (v5.5.28)
PHP5
I am using the following block of code in PHP:
try{
echo "PDO Connecting";
$Connection = PDO("mysql:host=localhost;dbname=my_database;charset=UTF-8", "username", "passwd");
echo "Connected";
}catch(PDOException $ex){
echo "Error!";
}
My problem is that I see the message PDO Connecting, and then nothing… No Connected message, nor error message… Any thoughts as to what the problem is and how to fix it?
Is PDO the best route? Or should I look into MySQLi instead?
EDIT
Results from var_dump(PDO::getAvailableDrivers());
array(2) { [0]=> string(5) “mysql” [1]=> string(6) “sqlite” }
Results from Apache error.log
PHP Fatal error: Call to undefined function PDO() in /path/to/file.php on line 33
You missed the “new” keyword.
Make sure that you turn the error_reporting on to catch further errors.