The original mysql_* function family was removed entirely in PHP 7 after years of deprecation — any codebase still calling mysql_query() simply won’t run on a modern PHP version. Migrating to mysqli or PDO is mandatory, not optional.
// Old, removed in PHP 7+
// $result = mysql_query("SELECT * FROM users WHERE id = $id");
// mysqli equivalent, with prepared statements
$mysqli = new mysqli('localhost', 'user', 'pass', 'app');
$stmt = $mysqli->prepare("SELECT * FROM users WHERE id = ?");
$stmt->bind_param('i', $id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
echo $row['name'];
}
Which Should You Migrate To?
PDO is generally the better target — it supports multiple database backends and has a cleaner API for named parameters — but mysqli is a valid choice too, especially for straightforward migrations where minimizing changed lines matters more than future database portability.