Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Call to undefined function mysql_pconnect() after a PHP upgrade

ErrorFatal error: Call to undefined function mysql_pconnect()

Short answer

The old mysql_* functions belonged to the ext/mysql extension, which PHP removed in version 7.0. On any current PHP they do not exist, so the call fails. In CodeIgniter, change the database driver from mysql to mysqli. In your own code, rewrite the calls with mysqli or PDO.

  • Applies to PHP 8.3, CodeIgniter 3.1
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask PHP which MySQL extensions are loaded. If mysqli or pdo_mysql is listed but mysql is not, the old functions cannot work.

    php -m | grep -i mysql
  2. 2Match what you see, then jump to its fix

    1. 1The config file says 'dbdriver' => 'mysql' and the error appears on the first database callCodeIgniter is still configured with the mysql driverFix
    2. 2The error names a function in your file, not in the frameworkYour own code calls the removed mysql_* functionsFix

What does the error look like?

  • Fatal error: Call to undefined function mysql_pconnect()
  • Call to undefined function mysql_connect()

Cause 1 of 2

CodeIgniter is still configured with the mysql driver

1Check

Open the database config and read the dbdriver value.

grep -n "dbdriver\|pconnect" application/config/database.php

2Fix

Set dbdriver to mysqli. The CodeIgniter manual gives mysqli as the MySQL value, in lower case.

$db['default']['dbdriver'] = 'mysqli';

3Verify

Load any page that touches the database.

curl -I http://localhost/index.php

Confirmed by codeigniter.com

Did this fix it?

Cause 2 of 2

Your own code calls the removed mysql_* functions

1Check

Search the project for the old calls, including libraries under vendor-style folders.

grep -rn "mysql_[a-z_]*(" --include=*.php .

2Fix

Rewrite them with mysqli. A persistent connection is the same pooled kind of connection that mysqli supports; it is controlled by the mysqli.allow_persistent directive.

$db = new mysqli('localhost', 'user', 'password', 'database');
if ($db->connect_errno) {
    exit('Connection failed: ' . $db->connect_error);
}
$result = $db->query('SELECT id, name FROM users');
while ($row = $result->fetch_assoc()) {
    echo $row['name'];
}

3Verify

Run the script from the command line.

php -l script.php && php script.php

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Run php -l and a search for mysql_ calls before changing the PHP version of a server.
  • Keep database settings in one config file so one change moves the whole app to mysqli.
  • Pin the PHP version in your deployment notes so framework and PHP stay in step.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.