What are the potential pitfalls of using mysql_connect and mysql_select_db in PHP?

Using mysql_connect and mysql_select_db in PHP is not recommended as they are deprecated functions and can pose security risks such as SQL injection. It is better to use mysqli or PDO for database connections in PHP to ensure better security and compatibility with newer versions of PHP.

// Connect to MySQL using mysqli
$mysqli = new mysqli("localhost", "username", "password", "database");

// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}