In PHP, what are the implications of using deprecated mysql functions for database connections and queries, and what are the recommended alternatives for modern development practices?

The use of deprecated mysql functions in PHP for database connections and queries poses security risks and compatibility issues with newer PHP versions. It is recommended to switch to modern alternatives like PDO (PHP Data Objects) or mysqli for database operations.

// Using PDO for database connection and query
$dsn = 'mysql:host=localhost;dbname=mydatabase';
$username = 'username';
$password = 'password';

try {
    $pdo = new PDO($dsn, $username, $password);
    $stmt = $pdo->query('SELECT * FROM mytable');
    while ($row = $stmt->fetch()) {
        // Process the data
    }
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}