LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-22-2011, 02:01 PM   #1
jasonfrost
LQ Newbie
 
Registered: Aug 2007
Location: Ohio
Distribution: Still experimenting....not sure
Posts: 7

Rep: Reputation: 0
Unhappy PHP error trying to connect to MySQL


First off, I am using CentOS 5.

I am getting this error when I try to connect to my MySQL database from a PHP page.
MySQL is working fine on it's own and PHP is working on it's own.

"Fatal error: Call to undefined function mysql_connect() in /usr/local/htdocs/test.php on line 11"

I have found instances on the Internet where other people had the same problem but from everything I've read, none of it appears to do anything for me.

I have read that I need the "extension=mysql.so" in my php.ini file and to uncomment it but it's not in there and I don't even have the "mysql.so" file.

Many people have said to install the MySQL "devel" package, which I have also done and it is still not adding the file. (Tried "rpm -i php-mysql")

I have also tried running the PHP ./configure again with the "--with-mysql".

After all of these I still can't seem to get any further than I was when I found out I had a problem.

If anyone can provide some assistance to point me in the right direction I would appreciate it. Thank you.

Last edited by jasonfrost; 03-22-2011 at 03:15 PM.
 
Old 03-22-2011, 03:55 PM   #2
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
Sometimes it depends on your distribution but if you're missing the mysql module for php (you can confirm with php -m), you'll need to install the php-mysql package (Red Hat naming scheme) or if all else fails I believe pecl install mysql may work.

Regards,

Alunduil
 
Old 03-22-2011, 04:03 PM   #3
jasonfrost
LQ Newbie
 
Registered: Aug 2007
Location: Ohio
Distribution: Still experimenting....not sure
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by alunduil View Post
Sometimes it depends on your distribution but if you're missing the mysql module for php (you can confirm with php -m), you'll need to install the php-mysql package (Red Hat naming scheme) or if all else fails I believe pecl install mysql may work.
Well I did install using the RPM though that's the thing I don't get. I used "rpm -i php-mysql" and it said it installed successfully... Did I type something wrong maybe?
 
Old 03-22-2011, 04:13 PM   #4
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
After that was there an /etc/php.ini.rpmnew file created? If so you may need to overwrite your current /etc/php.ini with that file to load the mysql module. Then don't forget to restart apache to reload the PHP configuration in your web environment.

Regards,

Alunduil
 
Old 03-22-2011, 08:52 PM   #5
jasonfrost
LQ Newbie
 
Registered: Aug 2007
Location: Ohio
Distribution: Still experimenting....not sure
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by alunduil View Post
After that was there an /etc/php.ini.rpmnew file created? If so you may need to overwrite your current /etc/php.ini with that file to load the mysql module. Then don't forget to restart apache to reload the PHP configuration in your web environment.
Hm nope. Don't have that file...

Only php.ini, php.ini-development, and php.ini-production.
 
Old 03-22-2011, 08:57 PM   #6
jasonfrost
LQ Newbie
 
Registered: Aug 2007
Location: Ohio
Distribution: Still experimenting....not sure
Posts: 7

Original Poster
Rep: Reputation: 0
I do have the file "mysql.sock"...Is this similar to ".so" files at all?

Ah nevermind. I believe .so is a source file..?

As I look more I don't appear to have the php-mysql module installed. In CentOS if I go into "Add/Remove Software" I see that there is the package "php-mysql-5.1.6-27...etc" that can be installed. When I try to install it though, I get the message: "mysql-devel conflicts with MySQL-devel mysql conflicts with MySQL-server".

I already have everything else installed...all I need is the php-mysql module installed. Is there anyway to have it installed and detect what I already have? Or maybe get a more up to date version of php-mysql?

Last edited by jasonfrost; 03-22-2011 at 10:55 PM.
 
Old 03-23-2011, 07:11 AM   #7
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
The sock file is a socket for communicating with the mysql server. A .so file is a shared object (dynamically linkable library).

I would try getting the output of yum install php-mysql so we can see what dependencies and errors are happening.

Regards,

Alunduil
 
Old 03-23-2011, 10:40 AM   #8
jasonfrost
LQ Newbie
 
Registered: Aug 2007
Location: Ohio
Distribution: Still experimenting....not sure
Posts: 7

Original Poster
Rep: Reputation: 0
Attached the yum output.
Attached Files
File Type: txt yum_output.txt (1.2 KB, 14 views)
 
Old 03-23-2011, 08:41 PM   #9
jasonfrost
LQ Newbie
 
Registered: Aug 2007
Location: Ohio
Distribution: Still experimenting....not sure
Posts: 7

Original Poster
Rep: Reputation: 0
I tried running "./configure --with-mysqli=/usr/bin/" which appears to be where I installed mysql but at a point I get to..

"mysql_config not found" But I already have the file right in /usr/bin/!!!! Why can't it see it?

/usr/bin is also in my PATH so wth.

Since it can't find that it must cause the whole thing to fail with the message "configure: error: Please reinstall the mysql distribution".

Last edited by jasonfrost; 03-24-2011 at 09:02 AM.
 
Old 03-26-2011, 03:35 AM   #10
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Hi Jason,

IMHO the easiest way is -

Configure LAMP stack as given here

Then create PHP file to connect to database
Code:
    # vim /var/www/html/connectdb.php
	<?php 
	mysql_connect("mail.example.com", "vicky", "vicky27") or die(mysql_error()) ; 
	mysql_select_db("vikas") or die(mysql_error()) ;
	?>
Here,
host=mail.example.com
db username=vicky
db password=vicky27
db name=vikas


Then, to test database connectivity, create another file which will call connectdb.php and do SQL operations.

Code:
vim /var/www/html/create_table.php
	<?
	include 'connectdb.php';

	mysql_query("CREATE TABLE mycustomers(customername VARCHAR(255) 
	CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, 
	PRIMARY KEY(customername), phonenumber INT NOT NULL, 
	address VARCHAR(255) CHARACTER SET utf8 COLLATE 
	utf8_unicode_ci NOT NULL, INDEX(phonenumber), 
	city VARCHAR(255) CHARACTER SET utf8 COLLATE 
	utf8_unicode_ci NOT NULL)")
	or die(mysql_error());  
	?>
Now, run the below command two times.

Run the below command two times.
Code:
    # curl -i http://mail.example.com:80/create_table.php
	HTTP/1.1 200 OK
	Date: Sat, 25 Dec 2010 08:41:40 GMT
	Server: Apache/2.2.3 (CentOS)
	X-Powered-By: PHP/5.1.6
	Content-Length: 0
	Connection: close
	Content-Type: text/html; charset=UTF-8

    #
    # curl -i http://mail.example.com:80/create_table.php
	HTTP/1.1 200 OK
	Date: Sat, 25 Dec 2010 08:42:12 GMT
	Server: Apache/2.2.3 (CentOS)
	X-Powered-By: PHP/5.1.6
	Content-Length: 34
	Connection: close
	Content-Type: text/html; charset=UTF-8

	Table 'mycustomers' already exists
    #
You should get an error "Table 'mycustomers' already exists". This shows that PHP was able to communicate with MySQL database through the http url.

Hope this helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
is there a client install for MySql so PHP can connect to MySQL Server? alar Linux - Software 8 07-03-2007 07:42 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. SpellChainz Linux - Newbie 1 06-23-2007 03:35 PM
PHP does not show any error message (when i try to connect with MySQL !) rean Fedora 2 12-27-2006 08:36 AM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration