What are the potential pitfalls of switching from PHP 4 to PHP 7 in terms of database connections and data retrieval?

Potential pitfalls of switching from PHP 4 to PHP 7 in terms of database connections and data retrieval include deprecated functions and changes in syntax that may cause errors or unexpected behavior. To solve this, it is important to update the code to use the newer mysqli or PDO extensions for database connections and data retrieval.

// PHP 4 style database connection
$connection = mysql_connect('localhost', 'username', 'password');
mysql_select_db('database_name', $connection);

// PHP 7 compatible database connection using mysqli
$connection = mysqli_connect('localhost', 'username', 'password', 'database_name');
if (!$connection) {
    die('Connection failed: ' . mysqli_connect_error());
}