A PHP library to query a database.
composer require michaelrushton/php-dbSee https://www.php.net/manual/en/pdo.exec.php.
$count = $connection->exec("DELETE FROM users");See https://www.php.net/manual/en/pdo.query.php.
$pdo_stmt = $connection->query("SELECT * FROM users");
$pdo_stmt = $connection->query("SELECT * FROM users", $fetchMode, ...$fetchModeArgs);See https://www.php.net/manual/en/pdo.prepare.php.
$pdo_stmt = $connection->prepare("SELECT * FROM users WHERE id = ?");
$pdo_stmt = $connection->prepare("SELECT * FROM users WHERE id = ?", $options);See https://www.php.net/manual/en/pdostatement.execute.php.
$pdo_stmt = $connection->execute("SELECT * FROM users WHERE id = ?", [1]);See https://www.php.net/manual/en/pdostatement.fetch.php.
$user = $connection->fetch("SELECT * FROM users WHERE id = ?", [1]);
$user = $connection->fetch("SELECT * FROM users WHERE id = ?", [1], $mode, $cursorOrientation, $cursorOffset);See https://www.php.net/manual/en/pdostatement.fetchall.php.
$users = $connection->fetchAll("SELECT * FROM users WHERE status = ?", [1]);
$users = $connection->fetchAll("SELECT * FROM users WHERE status = ?", [1], $mode, ...$args);See https://www.php.net/manual/en/pdostatement.fetchcolumn.php
$id = $connection->fetchColumn("SELECT * FROM users WHERE id = ?", [1]);
$id = $connection->fetchColumn("SELECT * FROM users WHERE id = ?", [1], $column);See https://www.php.net/manual/en/pdostatement.fetchobject.php
$user = $connection->fetchObject("SELECT * FROM users WHERE id = ?", [1]);
$user = $connection->fetchObject("SELECT * FROM users WHERE id = ?", [1], $class, $constructorArgs);See https://www.php.net/manual/en/pdostatement.fetch.php.
$generator = $connection->yield("SELECT * FROM users WHERE status = ?", [1]);
$generator = $connection->yield("SELECT * FROM users WHERE status = ?", [1], $mode, $cursorOrientation, $cursorOffset);Begins a transaction, rolls back if an exception is thrown (rethrowing the exception), else commits.
use MichaelRushton\DB\Connection;
$connection->transaction(function (Connection $connection)
{
$connection->query("INSERT INTO users (id) VALUES (1)");
$connection->query("INSERT INTO users (id) VALUES (2)");
});$count = $connection->delete()->from('users')->exec();$pdo_stmt = $connection->select()->from('users')->query();
$pdo_stmt = $connection->select()->from('users')->query($fetchMode, ...$fetchModeArgs);$pdo_stmt = $connection->select()->from('users')->where('id = ?')->prepare();
$pdo_stmt = $connection->select()->from('users')->where('id = ?')->prepare($options);$pdo_stmt = $connection->select()->from('users')->where('id', 1)->execute();$user = $connection->select()->from('users')->where('id', 1)->fetch();
$user = $connection->select()->from('users')->where('id', 1)->fetch($mode, $cursorOrientation, $cursorOffset);$users = $connection->select()->from('users')->where('status', 1)->fetchAll();
$users = $connection->select()->from('users')->where('status', 1)->fetchAll($mode, ...$args);$id = $connection->select()->from('users')->where('id', 1)->fetchColumn();
$id = $connection->select()->from('users')->where('id', 1)->fetchColumn($column);$user = $connection->select()->from('users')->where('id', 1)->fetchObject();
$user = $connection->select()->from('users')->where('id', 1)->fetchObject($class, $constructorArgs);$generator = $connection->select()->from('users')->where('status', 1)->yield();
$generator = $connection->select()->from('users')->where('status', 1)->yield($mode, $cursorOrientation, $cursorOffset);