-
Notifications
You must be signed in to change notification settings - Fork 0
ch10_databases
Daniel Samson edited this page Feb 19, 2025
·
2 revisions
Teensy PHP supports MySQL, PostgreSQL, SQLite, and MSSQL.
To initialize the database, you can use the Database::connect function.
use TeensyPHP\Utility\Database;
$db = Database::connect(
Config::get("DATABASE_ENGINE", "sqlite"),
Config::get("DATABASE_DATABASE", "teensy.sqlite"),
Config::get("DATABASE_HOST"),
Config::get("DATABASE_PORT"),
Config::get("DATABASE_USERNAME"),
Config::get("DATABASE_PASSWORD"),
);Once the database is connected, you can use the Database->connection() function to get the PDO connection.
$sql = "SELECT * FROM {$table} WHERE id = ?";
$statement = Database::connection()->prepare($sql);
$result = $statement->execute([$id]);
$records = $statement->fetchAll(\PDO::FETCH_ASSOC);