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— <?php
$db_host = “localhost”; $db_name =“xxxxxxxxx"; $username = “xxxxxxxxx"; $password = “xxxxxxxxxxxxx";
$dsn = “mysql:host=$db_host;dbname=$db_name;charset=utf8”; $opt = array( PDO::ATTR_ERRMODE => 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; ?>
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Try installing the PDO extension and the MySQL PDO driver: <br><pre>sudo apt-get install php5-pdo php5-mysql</pre>
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.