What are the potential pitfalls of using outdated PHP functions like mysql_query?

Using outdated PHP functions like mysql_query can pose security risks as they are deprecated and no longer supported, making your code vulnerable to SQL injection attacks. To solve this issue, it is recommended to use newer, more secure functions like mysqli or PDO for interacting with databases in PHP.

// Connect to database using mysqli
$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);
$stmt->execute();
$result = $stmt->get_result();

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

// Close statement and connection
$stmt->close();
$mysqli->close();