Connect using PHP PDO to mysql database failed

I’m using a droplet with Ubuntu 12.04 (32bits) and after installing LAMP into this droplet I cannot access from a php file to my database using the admin user from the site.

I updated my host, username and password to connect but I don’t know If I forgot any command or related tip.

The connection always return not successfull.

I great any notice about this error.


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

These a serie of eight videos deeply explaining how to connect to the database using PDO method. Enjoy watching them.

Many thanks both of you. I didn’t execute the sudo mysql_install_db command into my droplet.

Many thanks all your answers.

How are you trying to connect to the database? Are you catching the error message? That might give you a better idea of what the problem is. Try doing something like:

try {
    $conn = new PDO('mysql:host=localhost;port=1234;dbname=$dbname', $username, $password);
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();