Is it advisable to use MySQL functions like mysql_connect in PHP to manage database connections?
It is not advisable to use MySQL functions like mysql_connect in PHP to manage database connections as they are deprecated as of PHP 5.5.0 and removed in PHP 7.0.0. Instead, it is recommended to use the MySQLi or PDO extensions for connecting to a MySQL database in PHP.
// Using MySQLi extension to connect to a MySQL database
$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";