PDO connect DB Failed (Ubuntu 12.0.4 LAMP)

April 18, 2014 1.9k 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; ?>
2 Answers
Try installing the PDO extension and the MySQL PDO driver:
sudo apt-get install php5-pdo php5-mysql
Have another answer? Share your knowledge.