Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
03-22-2011, 02:01 PM
|
#1
|
LQ Newbie
Registered: Aug 2007
Location: Ohio
Distribution: Still experimenting....not sure
Posts: 7
Rep:
|
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.
|
|
|
03-22-2011, 03:55 PM
|
#2
|
Member
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684
Rep:
|
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
|
|
|
03-22-2011, 04:03 PM
|
#3
|
LQ Newbie
Registered: Aug 2007
Location: Ohio
Distribution: Still experimenting....not sure
Posts: 7
Original Poster
Rep:
|
Quote:
Originally Posted by alunduil
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?
|
|
|
03-22-2011, 04:13 PM
|
#4
|
Member
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684
Rep:
|
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
|
|
|
03-22-2011, 08:52 PM
|
#5
|
LQ Newbie
Registered: Aug 2007
Location: Ohio
Distribution: Still experimenting....not sure
Posts: 7
Original Poster
Rep:
|
Quote:
Originally Posted by alunduil
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.
|
|
|
03-22-2011, 08:57 PM
|
#6
|
LQ Newbie
Registered: Aug 2007
Location: Ohio
Distribution: Still experimenting....not sure
Posts: 7
Original Poster
Rep:
|
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.
|
|
|
03-23-2011, 07:11 AM
|
#7
|
Member
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684
Rep:
|
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
|
|
|
03-23-2011, 10:40 AM
|
#8
|
LQ Newbie
Registered: Aug 2007
Location: Ohio
Distribution: Still experimenting....not sure
Posts: 7
Original Poster
Rep:
|
Attached the yum output.
|
|
|
03-23-2011, 08:41 PM
|
#9
|
LQ Newbie
Registered: Aug 2007
Location: Ohio
Distribution: Still experimenting....not sure
Posts: 7
Original Poster
Rep:
|
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.
|
|
|
03-26-2011, 03:35 AM
|
#10
|
Senior Member
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 02:07 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|