I finally resolved problems with access to MySQL databases on a CentOS 7 server from the command line yesterday - see MySQL service not running on CentOS 7 system - but when I visited web pages on the server that rely upon PHP code to access MySQL databases on the server, I was seeing blank pages, though other PHP web pages that didn't have any database access were displaying properly. When I checked the Apache error log for a website where the PHP code should have displayed data from a database, I saw "PHP Fatal error: Call to undefined function mysql_connect()" associated with attempts to load the web page containing the PHP code that connected to the MySQL database.
I verified that the php-mysql
package was installed with
rpm -qi php-mysql
.
# rpm -qi php-mysql Name : php-mysql Version : 5.4.16 Release : 23.el7_0.3 Architecture: x86_64 Install Date: Tue 11 Nov 2014 08:26:15 PM EST Group : Development/Languages Size : 237259 License : PHP Signature : RSA/SHA256, Fri 31 Oct 2014 10:24:56 AM EDT, Key ID 24c6a8a7f4a80eb5 Source RPM : php-5.4.16-23.el7_0.3.src.rpm Build Date : Fri 31 Oct 2014 09:07:27 AM EDT Build Host : worker1.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem <http://bugs.centos.org> Vendor : CentOS URL : http://www.php.net/ Summary : A module for PHP applications that use MySQL databases Description : The php-mysql package contains a dynamic shared object that will add MySQL database support to PHP. MySQL is an object-relational database management system. PHP is an HTML-embeddable scripting language. If you need MySQL support for PHP applications, you will need to install this package and the php package.
I created a PHP test page with the following code:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<h2>A test page</h2>
<?php echo "<p>Hello world</p>"; ?>
<?php phpinfo(); ?>
</body>
</html>
"Hello world" was displayed by the PHP echo command and the information from the phpinfo function was also displayed. I searched through the results displayed for references to "MySQL" and found mysql and mysqli sections, including the following:
mysql
MySQL Support | enabled |
---|---|
Active Persistent Links | 0 |
Active Links | 0 |
Client API version | 5.5.37-MariaDB |
MYSQL_MODULE_TYPE | external |
MYSQL_SOCKET | /var/lib/mysql/mysql.sock |
MYSQL_INCLUDE | -I/usr/include/mysql |
MYSQL_LIBS | -L/usr/lib64/mysql -lmysqlclient |
Since it appeared that PHP support for MySQL was present,
I restarted Apache with apachectl restart
, though I
didn't expect that to resolve the problem. But when I refreshed
the web page afterwards, the information from the MySQL database
was displayed. Apparently, I should have restarted Apache
after I ran the systemctl start mariadb.service
to start the MariaDB database service yesterday. MariaDB is a
fork
of MySQL.
References:
-
Fatal error: Call to undefined function mysql_connect()
Date: May 16, 2012
stackoverflow -
Resolving a Fatal error: Call to undefined function mysql_connect() in RedHat
By: Shailesh N. Humbad
Created: October 18, 2004
Last Modified: July 24, 2011
Somacon
Articles on web development, software, and hardware