PDO connect DB Failed (Ubuntu 12.0.4 LAMP)

Posted April 18, 2014 4.4k views
Hi. I am trying to connect to a database (i have setup using phpmyadmin) thru a script (i.e.config script) i have placed in the “home/user" directory whereas the PHP GET script is placed in the “var/www" directory. When i run the GET script that attempt to connect to the database via config script, connection did not work and no error being echo. I know my GET script has successfully link to config script because i received the echo “config". My scripts have been tried out successfully in other web servers. Do i need to install PDO or ? Badly need advices on this. --config script--- PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); echo "config”; //i can see this echo from the browser try { $dbh = new PDO($dsn,$username,$password, $opt); echo $dbh; //cannot see this echo } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } // create LM object, pass in PDO connection $lm = new lazy_mofo($dbh); echo $lm; ?>

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers
Try installing the PDO extension and the MySQL PDO driver:
sudo apt-get install php5-pdo php5-mysql