Report this

What is the reason for this report?

PHP-MYSQL connection not working

Posted on January 16, 2015

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

file.



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!

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.

What OS have you got?

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

restart apache

Try this:

sudo apt-get install php5-mysqlnd

To install a further php5 package.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.