Resolving a Fatal error: Call to undefined function mysql_connect() in RedHat

18 篇文章 0 订阅
8 篇文章 0 订阅

Symptoms

In RedHat Linux, you have installed the PHP, MySQL, and Apache packages through the package manager. After starting the MySQL and Apache services through the service manager, you write a simple test php page to access the MySQL database. When the page is loaded in the web browser, you receive the error, Fatal error: Call to undefined function mysql_connect().

Sample Code

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

Cause

The mysql.so extension library does not come with the PHP or MySQL distributions. It must be installed separately by downloading the php-mysql RPM.

Fix

  1. Verify that your installation of PHP has been compiled with mysql support. Create a test web page containing <?php phpinfo(); exit(); ?> and load it in your browser. Search the page forMySQL. If you don't see it, you need to recompile PHP with MySQL support, or reinstall a PHP package that has it built-in, both of which are beyond the scope of this document.
  2. Verify that the line to load the extension in php.ini has been uncommented. In Linux, the line isextension=mysql.so and in Windows, the line is extension=php_mysql.dll. Uncomment the line by removing the semi-colon. You might also need to configure the extension_dir variable.
  3. Check if the php-mysql package is installed by opening a terminal window (bash), and typing,rpm -qa | grep php. If you don't see it, make a note of the exact version of PHP that is installed.
  4. Find the php-mysql RPM for the version of PHP that is installed on your system. The easiest way to find it is to search by the version of RedHat you have. Go to a RedHat mirror or look on your RedHat CDs. If you have RedHat 8.0, then navigate to the folder/linux/8.0/en/os/i386/RedHat/RPMS/ and search for php-mysql. Download this file. (For a list of mirror sites, try RedHat Mirrors or search Google for redhat mirrors.)
  5. To install the file, open a terminal window and cd to the directory where you saved the RPM. Then type rpm -hivv php-mysql-4.2.2-17.i386.rpm and press enter. This will install the RPM for RedHat 9.0.
  6. You might also need MySQL-shared-compat RPM if you get a dependency of libmysqlclient.so.10error while installing.
  7. The last step is to restart Apache. You can do this with one of the following commands,apachectl restart or /etc/rc.d/init.d/httpd restart.

Applies To

RedHat 7.x, 8.0, 9.0, Fedora, Apache, MySQL


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值