What are the advantages of switching from mysql to mysqli for database connections in PHP scripts?
Switching from mysql to mysqli for database connections in PHP scripts offers several advantages such as improved security, support for prepared statements, and better performance. Using mysqli also allows for better error handling and support for transactions.
// MySQL connection
$mysqli = new mysqli('localhost', 'username', 'password', 'database_name');
// Check connection
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}