What are some potential pitfalls when using the mysql_* functions in PHP and why is it recommended to switch to mysqli or PDO instead?

Using the mysql_* functions in PHP is not recommended as they are deprecated and no longer maintained. This can lead to security vulnerabilities, as these functions do not support prepared statements or parameterized queries, making your code more susceptible to SQL injection attacks. It is highly recommended to switch to mysqli or PDO for database interactions in 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);
}