HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Installation/Configuration (http://www.howtoforge.com/forums/forumdisplay.php?f=16)
-   -   The classic MySQL connect error (http://www.howtoforge.com/forums/showthread.php?t=12937)

swggy 25th May 2007 22:33

The classic MySQL connect error
 
Newbie speaking…

I've followed the 'perfect setup for CentOS 5.0' and I've got everything running fairly well. However, I can't fire up my test MySQL script - I get
Quote:

Fatal error: Call to undefined function mysql_connect() in /var/www/web8/web/.../mysql_up.php on line 12
So I went to the search engine and found 42,900 occurrences of this. I've poked around in the forums and found near hits to answer my problem, but nothing exact - one of the problems I'm bumping into is that so many of the answers presume that PHP is running on Windows, which doesn't really help me.

* I understand that MySQL isn't turned on by default in PHP5.
* I understand that MySQL is loaded on my system, since I'm running ISPConfig and it uses MySQL.
* I understand that my PHP probably doesn't have MySQL installed as an extension, since phpinfo says
Quote:

'--with-apxs2=/usr/sbin/apxs' '--without-mysql' '--without-gd'
and there's no table further down for it (I rather thought that 'the perfect setup' for a LAMPS install would automatically have php with MySQL, but that's another story.)

So I'm wondering - how to activate MySQL in PHP5, and it seems as if I have to recompile PHP. I’ve got 3 questions:

1) I’m guessing that I can take the entire configure command in the big box at the top of the phpinfo() display and run that (tweaking the ‘-–without-mysql’ of course). True?
2) What directory do I run this from? There’s a pile of ‘.h’ files in ‘/usr/include/php/main’ - do I go there? Or where?
3) Do I need anything else?

Thanks for any help ...
swggy

till 26th May 2007 15:29

Quote:

1) I’m guessing that I can take the entire configure command in the big box at the top of the phpinfo() display and run that (tweaking the ‘-–without-mysql’ of course). True?
No. Mysql is compiled fine. What all the sources you found in the internat take not in account that today all php installations are compiled modular, so --without-mysql just means that mysql is loaded as module and not compiled in.

Quote:

2) What directory do I run this from? There’s a pile of ‘.h’ files in ‘/usr/include/php/main’ - do I go there? Or where?
Do not do this if you dont want to mess up your installation!

Quote:

3) Do I need anything else?
Yes :)

1) Make sure that you have the php mysql module installed:

yum install php-mysql

If the command says that it is already installed, you must check if the module is loaded. Have a look at the php.ini file, the file is most likely in /etc/php5/apache2/ php.ini or a similar location in the /etc directory.

There must be a line in the file like:

extension=mysql.so

if you do not have this line, add it at the end of the file and restart your apache webserver.

swggy 26th May 2007 18:04

Thanks, but that didn't fix it ...
  • I did 'yum install php-mysql' and got back 'nothing to do'.
  • Then I found that mysql.so wasn't in the ini file, so I added 'extension=mysql.so' to the bottom of the file as you said, but nothing changed.
  • I then tried moving it to the extensions area instead, but nothing.
  • I also tried adding mysqli.so there, since I'm reading that PHP5 takes mysqli instead of mysql, but nothing.

I can get in through Putty on the CLI with
Quote:

mysql --user=swggy test
...of course that's not PHP, but it does confirm that the username and no pwd gets access.

phpinfo says my config file is /etc/php.ini (which is the file I've been making your changes to), and it says that 'extension_dir=./' - is that OK? The tables at the bottom of the phpinfo report jump straight from 'mime_magic' to 'openssl', so adding the 'extension=mysql.so' doesn't seem to have had any effect...
I also see that I have the following in /usr/lib/php/modules:
Quote:

file:///usr/lib/php/modules/dom.so
file:///usr/lib/php/modules/gd.so
file:///usr/lib/php/modules/imap.so
file:///usr/lib/php/modules/ldap.so
file:///usr/lib/php/modules/mysqli.so
file:///usr/lib/php/modules/mysql.so
file:///usr/lib/php/modules/odbc.so
file:///usr/lib/php/modules/pdo_mysql.so
file:///usr/lib/php/modules/pdo_odbc.so
file:///usr/lib/php/modules/pdo.so
file:///usr/lib/php/modules/pdo_sqlite.so
file:///usr/lib/php/modules/phpcups.so
file:///usr/lib/php/modules/xmlreader.so
file:///usr/lib/php/modules/xmlrpc.so
file:///usr/lib/php/modules/xmlwriter.so
file:///usr/lib/php/modules/xsl.so
So I may be a little further, but not there yet. Any other thoughts?
- thanks.

pyro 29th May 2007 15:51

i have same problem on perfect suse 10.2
isconfig is working, phpmyadmin is working - all users can login and root has all mysql privileges but when i test script to connect mysql then there is mysql_connect error message... :confused:

swggy 29th May 2007 21:47

Contrary to your response, the PHP site itself here... http://us2.php.net/mysql says clearly that for PHP 5 on a Linux OS, PHP needs to be reconfigured before MySQL is supported:
Quote:

PHP 5+

MySQL is not enabled by default, nor is the MySQL library bundled with PHP. Read this FAQ for details on why. Use the --with-mysql[=DIR] configure option to include MySQL support. You can download headers and libraries from MySQL.
Are you wrong? Are they wrong? Am I missing something? Everything still seems to point to the need to reconfigure with the MySQL optin turned on. I just don't have an answer yet. Maybe I need to ask on another forum?

swggy 29th May 2007 22:03

Pyro - once I get a response that fixes my problem I'll post it.

till 29th May 2007 22:42

Quote:

Are you wrong?
No.

Quote:

Are they wrong?
No.

Quote:

Am I missing something?
Yes. You neither read what I said not what they said properly. php.net is talking about statically compiled in mysql support which is not used anymore in most linux distributions. They all use modular PHP now where the mysql module is loaded in form of a mysql.so file.

But if you want to mess up your setup, please recompile it.

Please post the output of:

locate php.ini

Also set:

extension_dir=/usr/lib/php/modules

in all php.ini files that you find in /etc and its subdirectories.

till 29th May 2007 22:44

Quote:

i have same problem on perfect suse 10.2
isconfig is working, phpmyadmin is working - all users can login and root has all mysql privileges but when i test script to connect mysql then there is mysql_connect error message...
run:

yast -i php-mysql

swggy 29th May 2007 23:09

Here's the output - it's only in /etc
Quote:

[root@server ~]# locate php.ini
/etc/AAAphp.ini
/etc/php.ini
/etc/php.ini~
/root/.kde/share/apps/RecentDocuments/php.ini.desktop
/root/ispconfig/php/php.ini~
/root/ispconfig/php/root%2fispconfig%2fphp%2fphp.ini.old
... and hey, presto, changing 'extension_dir=./' to 'extension_dir=/usr/lib/php/modules' did the trick.

Don't be too grumpy with the newbie - I'm vey grateful.

Thanks.

pyro 30th May 2007 13:25

yess- extension_dir=/usr/lib/php5/modules did the trick.


tnx'!


All times are GMT +2. The time now is 01:34.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.