PHP-MYSQL connection not working

Hello Eveyone,

I have just started working with php-mysql besides my daily job and since few days I am banging my head resolving the connection problem between Apache, PHP and MySQL.

Firstly I deinstalled all the PHP and mysql things that comes with Linux distro and then installed mysql 5.6.22 and php 5.6.4 on my rhel6 machine and configured php

from source using below command.

./configure --with-apxs2=/usr/sbin/apxs --with-mysql

After this I wrote a some code to check connection between mysql and php. Here it goes:

<?php $host_name = “localhost”; $database = “rating”; // Change your database name $username = “rate”; // Your database user id $password = “rate”; // Your password

//////// Do not Edit below ///////// try { $dbo = new PDO(‘mysql:host=’.$host_name.‘;dbname=’.$database, $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo “Connected successfully”; } catch (PDOException $e) { print "Error!: " . $e->getMessage() . “<br/>”; echo "Connection failed: " . $e->getMessage(); die(); } ?>

This throws me an error driver not found. After googling i came to know there could be missing PDO drivers and have to install that. Please help me to resolve this.

How toget my php-mysql connection working. Please help. Is my configuration command above incorrect. Please guide me and what all changes need to be done in php.ini


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.

Try this:

sudo apt-get install php5-mysqlnd

To install a further php5 package.

What OS have you got?

If its centos… try: yum install php-pdo php-mysqli

restart apache