$dsn = 'mysql:host=localhost;dbname=mydatabase'; $username = 'myusername'; $password = 'mypassword'; $options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; $pdo = new PDO($dsn, $username, $password, $options);
$dsn = 'sqlite:/path/to/database.sqlite'; $pdo = new PDO($dsn);This example shows how to connect to a SQLite database using PDO. We only need to provide the DSN for the database file location. Package library: PDO is a core PHP extension and does not require any additional package library.