PHP not connecting to a MySQL database server

by nixcraft · 6 comments

Q. I have Apache Web server and MySQL configured. Everything works fine except I am not able to connect to a MySQL database server (I am able to connect mysql server with mysql client). So how do I configure or connect PHP scripts?

A. You need to install MySQL module for php4 or php5. Without php-mysql shared object or module, php scripts won't able to connect to MySQL database server.

Debian / Ubuntu Linux User

To install type the following command:
# apt-get install php4-mysql
if you are using PHP5, enter:
# apt-get install php5-mysql

RHEL <= 4 user

If you are using Red Hat Linux:
# up2date php-mysql

If you are using Fedora / CentOS / RHEL 5 Linux:
# yum install php-mysql
Restart apache to take effect. Now you will be able to connect MySQL via PHP scripts.
# service httpd restart

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 6 comments… read them below or add one }

1 rajesh 12.20.07 at 4:25 pm

I m not able to connect localhost. error 3306

2 Bill Brinegar 01.22.09 at 11:19 pm

I reat the following message and am having the same problem. I used XAMPP to install the group for windows vista. I have also installed them individually for the internet and also from a disk I got from a SAMs book.

I have Apache Web server and MySQL configured. Everything works fine except I am not able to connect to a MySQL database server (I am able to connect mysql server with mysql client). So how do I configure or connect PHP scripts?

I don’t understand the following answer, do I need to re-install MySQL or can I modify it? I would like to get all of them installed and be able to use mysqli functionality.

I have followed all of the different install proceedures and still can not get it to worl.

A. You need to install MySQL module for php4 or php5. Without php-mysql shared object or module, php scripts won’t able to connect to MySQL database server.

3 rishi 02.02.09 at 7:12 pm

i have my own domain and webserver i cant understand that why connection cannot be made to database of mysql with php

4 jayendra 07.05.09 at 8:26 pm

I am using wamp server and netbeans ide to write php. I am new to php development. I am not able to connect mysql to php. I don’t know what is happening? I am not able to insert data into mysql.

5 viji 11.13.09 at 5:49 am

why this error message in happens:
Could not connect: Access denied for user ’sss’@'localhost’ (using password: YES)

6 kuldeep singh 12.03.09 at 6:05 pm

hi i m new user to ubuntu.i could not connect to mysql server through php.
i have installed php5 ,mysql server ,apache server.
somebody can help me?????

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All