PHP error guide
Call to undefined function mysql_connect: meaning and fix
Error summary
Migrate connection and queries to PDO or mysqli with prepared statements. PHP 7+ no longer includes the removed ext/mysql API.
What it means
Migrate connection and queries to PDO or mysqli with prepared statements. PHP 7+ no longer includes the removed ext/mysql API.
What the error means
This message means that PHP 7+ no longer includes the removed ext/mysql API. The exact signature distinguishes call to undefined function mysql_connect from a generic application failure.
Why PHP produces it
The engine or service reports “Call to undefined function mysql_connect” because its required precondition was not met. Migrate connection and queries to PDO or mysqli with prepared statements.
PHP version notes
The call to undefined function mysql_connect wording here is based on PHP 7.0+; punctuation and exception class names can differ on older branches or vendor builds.
Most common causes
- The immediate input or configuration reaches the specific condition: PHP 7+ no longer includes the removed ext/mysql API
- The code path assumes the prerequisite for call to undefined function mysql_connect has already been satisfied.
- For call to undefined function mysql_connect, development and production differ in version, extension, permissions, paths, or service configuration.
- An earlier operation returned an unchecked value that is consumed by the line reporting call to undefined function mysql_connect.
Minimal examples
BAD — reproduces the problem
$db = mysql_connect("localhost","u","p");
FIXED — safer pattern
$db = new PDO($dsn, $user, $pass, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
Step-by-step diagnosis
- Copy the complete “Fatal error: Uncaught Error: Call to undefined function mysql_connect()” text and retain the first application stack frame.
- Reproduce call to undefined function mysql_connect in the same SAPI and environment listed for this page.
- Before changing call to undefined function mysql_connect, inspect the preceding value or directive and verify its type, path, version, and permissions.
- Apply the narrow correction—migrate connection and queries to PDO or mysqli with prepared statements—then repeat the original request once.
Fixes
Correct the failing prerequisite
Migrate connection and queries to PDO or mysqli with prepared statements
$db = new PDO($dsn, $user, $pass, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
Fail explicitly at the boundary
Validate the condition before the operation that emits call to undefined function mysql_connect, and log a safe diagnostic without credentials or full production paths.
Common mistakes when fixing it
- Suppressing call to undefined function mysql_connect instead of correcting its upstream condition.
- Testing call to undefined function mysql_connect only with the CLI binary when the failing request runs under FPM or Apache.
- Changing a global setting for call to undefined function mysql_connect before confirming the site-specific effective configuration.
How to prevent it
- Add a focused test that exercises the boundary responsible for call to undefined function mysql_connect.
- Keep runtime versions, extensions, configuration, and deploy artifacts affecting call to undefined function mysql_connect reproducible.
- Validate external data and service return values before they can trigger call to undefined function mysql_connect.
Modernization guides
Web server / environment notes
apache, fpm, shared-hosting. The failure occurs where pHP 7+ no longer includes the removed ext/mysql API
Tags: apache,fpm,shared-hosting