1

I am running a simple test script from the command line on CentOS 5.6 with the PHP package installed from PHP 5.3 on CentOS/RHEL 5.6.

PHP runs fine in all other cases but when I hit mysql_connect() it fails without error.

If I run

$ php -m

I am not seeing MySQL as an installed module.

However I have added extension=mysql.so to my php.ini and rebooted.

Output of 'rpm -qa | grep php'

php-common-5.3.10-1.w5
php-5.3.10-1.w5
php-cli-5.3.10-1.w5

Output of 'yum install php-mysql'

  --> Missing Dependency: php-common = 5.1.6-27.el5_7.5 is needed by package php-mysql-5.1.6-27.el5_7.5.x86_64 (updates)
php-pdo-5.1.6-27.el5_7.5.x86_64 from updates has depsolving problems
  --> Missing Dependency: php-common = 5.1.6-27.el5_7.5 is needed by package php-pdo-5.1.6-27.el5_7.5.x86_64 (updates)
Error: Missing Dependency: php-common = 5.1.6-27.el5_7.5 is needed by package php-pdo-5.1.6-27.el5_7.5.x86_64 (updates)
Error: Missing Dependency: php-common = 5.1.6-27.el5_7.5 is needed by package php-mysql-5.1.6-27.el5_7.5.x86_64 (updates)
 You could try using --skip-broken to work around the problem
 You could try running: package-cleanup --problems
                        package-cleanup --dupes
                        rpm -Va --nofiles --nodigest
The program package-cleanup is found in the yum-utils package.

2 Answers 2

6
 I am not seeing MySQL as an installed module.

Did you install it?

# yum install php-mysql

(from the same repo you installed php from).

EDIT:

run this:

yum --enablerepo=webtatic install php-mysql

this tells yum to get the packages from webtatic repository (in addition to system configured repositories). If you want webtatic among system enabled repositories, run:

 yum --enablerepo=webtatic install  webtatic-release
Sign up to request clarification or add additional context in comments.

8 Comments

If you have yum installed, "yum install php-mysql" should do it, if it's not already installed
how did you install package php? if you installed it with yum, run on the command line, yum install php-mysql as root
Ok, installed. BTW, is there any way to restart php w/o reboting the server? usually I can just restart apache to see changes take effect but cannot in this instance.
php is not a service, so it does not need restart; when you install php itself, as an apache module, it's apache which needs reloading; but in this case you just installed a php library, mysql connection should work out of the box (mysql package is installed for sure if you used yum, just check if it is running).
Rebooted. Still no luck. Getting: Fatal error: Call to undefined function mysql_connect() in /home/app/index.php on line 7
|
0

First, some advice: stop using mysql libraries and use PDO or at least the mysqli libraries.

Now for some troubleshooting help: the first step is to be 100% sure the mysql is loading. Create a script (web based) with:

phpinfo();

Confirm that somewhere on this page there is a block indicating that the mysql extension is being loaded.

Wherever you are testing an are uncertain of errors, right before you call mysql_connect add these lines:

ini_set('display_errors', 1);
ini_set('log_errors', 1); 
error_reporting(E_ALL | E_STRICT);

This will ensure you aren't suppressing the errors somewhere else before the connect. Some frameworks sometimes do this.

If it's indeed the module is loading and with the added error logging code you still don't get a valid error. I'd try connecting in a command line php script. Look in the php.ini file to see what "error_log" is set to. This is the default log it will it will log to--sometime http based settings override logging, so even if errors are thown, you don't see or can't find them. A command line php script factors this out.

Last but not least, you can always post your connection string to this post. Try connecting from the command line on the server as your script using the mysql command with the same credentials as your mysql_connect. You might be able to connecting just fine, but have bad credentials.

If the module is not loading, try to find exactly where the module resides and put the full path into the php.ini. Yum sometimes installs stuff not where php.ini is looking for it. At the end of the Yum install, it sometimes tells you the path, if not, to find it with brute force, do this:

cd /
find . -name 'mysql.so'

so in the php.ini, instead of

extension=mysql.so

put

extension=/path/to/found/mysql.so

Good luck!

3 Comments

I am getting the following error: Fatal error: Call to undefined function mysql_connect() in /home/app/index.php on line 7 The module does not appear to be loaded even though I have now installed MySQL 'yum install php-mysql'
Did you run the phpinfo() to be 100% sure it's not loading (the fatal error does point to that, but I like to be extra sure)
@phirschybar I added some help for finding where yum may have dumped the mysql library, sometimes it's not where php.ini expects them to be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.