Which database library is recommended for handling multiple databases and tables in PHP?

When handling multiple databases and tables in PHP, it is recommended to use the PDO (PHP Data Objects) library. PDO provides a consistent interface for accessing different types of databases, making it easier to switch between database systems without changing your code. It also supports prepared statements, which helps prevent SQL injection attacks.

// Connect to a MySQL database using PDO
$dsn = 'mysql:host=localhost;dbname=mydatabase';
$username = 'username';
$password = 'password';

try {
    $pdo = new PDO($dsn, $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}