What are the differences between using MySQL and MySQLi in PHP?
When working with databases in PHP, there are two main ways to interact with MySQL databases: using the MySQL extension or the MySQLi extension. MySQLi (MySQL Improved) is a newer and more feature-rich extension that provides a more secure and efficient way to interact with MySQL databases compared to the older MySQL extension. It supports prepared statements, transactions, and other advanced features that make database interactions more secure and efficient.
// Using MySQLi extension to connect to a MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "Connected successfully";
}