What are common reasons for the "Call to undefined function mysql_connect()" error in PHP scripts running on Linux?
The "Call to undefined function mysql_connect()" error in PHP scripts running on Linux typically occurs when the MySQL extension is not enabled or installed on the server. To solve this issue, you can switch to using the MySQLi or PDO extension for connecting to MySQL databases, as the original MySQL extension is deprecated in PHP 7 and removed in PHP 7.0.0.
// Connect to MySQL database using MySQLi extension
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
Keywords
Related Questions
- What best practices should be followed when working with image metadata in PHP to ensure accurate extraction and utilization of the data stored within the files?
- Are there any best practices for creating custom PHP functions or commands?
- How does the PHP memory limit affect the execution of scripts that generate ZIP files for download or server storage?