What are the potential pitfalls of using the mysql_ functions in PHP, and why is it recommended to switch to mysqli or PDO?

The potential pitfalls of using the mysql_ functions in PHP include security vulnerabilities such as SQL injection attacks and lack of support for newer MySQL features. It is recommended to switch to mysqli or PDO as they provide prepared statements and parameterized queries, which help prevent SQL injection attacks, as well as support for features like stored procedures and transactions.

// Using mysqli to connect to a MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

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

// Using PDO to connect to a MySQL database
$pdo = new PDO("mysql:host=localhost;dbname=database", "username", "password");

if (!$pdo) {
    die("Connection failed: " . $pdo->errorInfo());
}