What are common pitfalls when using deprecated PHP functions like mysql_connect and mysql_query?

Deprecated PHP functions like mysql_connect and mysql_query are no longer supported in newer PHP versions, and continued use of these functions can lead to security vulnerabilities and compatibility issues. To solve this problem, you should switch to using the improved MySQLi or PDO extensions for connecting to a MySQL database and executing queries.

// Connect to MySQL database using MySQLi
$mysqli = new mysqli("localhost", "username", "password", "database");

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

// Execute a query using MySQLi
$result = $mysqli->query("SELECT * FROM table");

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

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