What are the potential pitfalls of using the mysql_* functions in PHP and why are they considered outdated?

The potential pitfalls of using the mysql_* functions in PHP include security vulnerabilities such as SQL injection attacks, lack of support for modern MySQL features, and the functions being deprecated in newer PHP versions in favor of the mysqli or PDO extensions. To solve this issue, it is recommended to switch to either the mysqli or PDO extensions, which offer more secure and feature-rich ways to interact with MySQL databases.

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

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

// Perform a query using prepared statements
$stmt = $mysqli->prepare("SELECT * FROM table WHERE column = ?");
$stmt->bind_param("s", $value);
$value = "example";
$stmt->execute();
$result = $stmt->get_result();

// Fetch results
while ($row = $result->fetch_assoc()) {
    // Do something with the data
}

// Close connection
$mysqli->close();