2 min read Sep 26, 2026

Fix “Call to undefined function mysql_connect()”

The old PHP mysql extension no longer exists in modern PHP. Learn why mysql_connect() fails and how to move your code to mysqli or PDO, with a short example of each.

FimuroHost Team

FimuroHost Team

Technical Writer

Share Article

If an older PHP script shows Fatal error: Uncaught Error: Call to undefined function mysql_connect(), nothing is wrong with your hosting. The script uses a PHP extension that no longer exists.

What happened to the mysql extension?

The original mysql_* functions (mysql_connect, mysql_query, mysql_fetch_array and so on) were deprecated in PHP 5.5 and removed completely in PHP 7.0. Since then, PHP has offered two replacements:

  • mysqli, the "MySQL improved" extension, which works in a similar way to the old functions
  • PDO_MySQL, PHP's database-independent interface, which is great for new code

Both are installed on FimuroHost Cloud Hosting and work with the platform's MariaDB servers.

The right fix: update the code

For third-party software, install a current release. Maintained apps switched to mysqli or PDO years ago. For your own code, replace the old calls. Here's a typical before-and-after:

Old (no longer works)

$link = mysql_connect('localhost', 'user', 'pass');
mysql_select_db('mydb', $link);
$result = mysql_query("SELECT * FROM users WHERE id = $id");

New with mysqli

$db = new mysqli('your-db-hostname.hosting.stackcp.net', 'user', 'pass', 'mydb');
$stmt = $db->prepare('SELECT * FROM users WHERE id = ?');
$stmt->bind_param('i', $id);
$stmt->execute();
$result = $stmt->get_result();

New with PDO

$pdo = new PDO('mysql:host=your-db-hostname.hosting.stackcp.net;dbname=mydb;charset=utf8mb4', 'user', 'pass');
$stmt = $pdo->prepare('SELECT * FROM users WHERE id = ?');
$stmt->execute([$id]);
$rows = $stmt->fetchAll();

Prepared statements (the ? placeholders) also protect you from SQL injection, which the old code was wide open to. Remember to use your StackCP database hostname rather than localhost.

For more detail, see the PHP manual's guide to choosing a MySQL API.

Last resort: an old PHP version

PHP 5.3–5.6 still include the old mysql module. If StackCP's Switch PHP Version tool still lists one of them, you could run an old script on it temporarily. Be aware that these versions are long past end of life and get no security fixes. Treat this as a short bridge while you update or replace the code, not a permanent setup.

Need help?

If something doesn't work as described, open a support ticket from your client area or message us on WhatsApp at 01818160926. Tell us the domain name and what you have already tried, and we'll take it from there.

FimuroHost Team

Written by

FimuroHost Team

Technical Writer