What are the potential pitfalls of using mysql_ functions in PHP and what alternatives should be used instead?

Using mysql_ functions in PHP is discouraged as they are deprecated and insecure. Instead, developers should use MySQLi or PDO extensions for database operations in PHP to ensure better security and compatibility with newer versions of PHP.

// Using MySQLi extension
$mysqli = new mysqli("localhost", "username", "password", "database");

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

// Perform database operations using prepared statements

$mysqli->close();