How can the error message "Fatal error: Call to undefined function mysql_connect()" be resolved in PHP scripts?
The error "Fatal error: Call to undefined function mysql_connect()" occurs when the MySQL extension is not enabled in PHP. To resolve this issue, you can switch to using the MySQLi or PDO extension for connecting to a MySQL database instead.
// Example using MySQLi extension
$mysqli = new mysqli('localhost', 'username', 'password', 'database_name');
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
Related Questions
- How can the issue of updating quantities in a shopping cart be resolved when only the last item is affected and the total value is multiplied instead of adjusting individual prices?
- What are the common challenges faced by PHP beginners when formatting numbers with decimal and thousand separators?
- What is the best way to transfer a PHP array to a JavaScript variable?