michaelrushton/db
Composer 安装命令:
composer require michaelrushton/db
包简介
A PHP library to query a database.
README 文档
README
A PHP library to query a database.
Installation
composer require michaelrushton/php-db
Documentation
Drivers
Connection
exec
See https://www.php.net/manual/en/pdo.exec.php.
$count = $connection->exec("DELETE FROM users");
query
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);
prepare
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);
execute
See https://www.php.net/manual/en/pdostatement.execute.php.
$pdo_stmt = $connection->execute("SELECT * FROM users WHERE id = ?", [1]);
fetch
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);
fetchAll
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);
fetchColumn
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);
fetchObject
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);
yield
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);
transaction
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)"); });
Query builders
exec
$count = $connection->delete()->from('users')->exec();
query
$pdo_stmt = $connection->select()->from('users')->query(); $pdo_stmt = $connection->select()->from('users')->query($fetchMode, ...$fetchModeArgs);
prepare
$pdo_stmt = $connection->select()->from('users')->where('id = ?')->prepare(); $pdo_stmt = $connection->select()->from('users')->where('id = ?')->prepare($options);
execute
$pdo_stmt = $connection->select()->from('users')->where('id', 1)->execute();
fetch
$user = $connection->select()->from('users')->where('id', 1)->fetch(); $user = $connection->select()->from('users')->where('id', 1)->fetch($mode, $cursorOrientation, $cursorOffset);
fetchAll
$users = $connection->select()->from('users')->where('status', 1)->fetchAll(); $users = $connection->select()->from('users')->where('status', 1)->fetchAll($mode, ...$args);
fetchColumn
$id = $connection->select()->from('users')->where('id', 1)->fetchColumn(); $id = $connection->select()->from('users')->where('id', 1)->fetchColumn($column);
fetchObject
$user = $connection->select()->from('users')->where('id', 1)->fetchObject(); $user = $connection->select()->from('users')->where('id', 1)->fetchObject($class, $constructorArgs);
yield
$generator = $connection->select()->from('users')->where('status', 1)->yield(); $generator = $connection->select()->from('users')->where('status', 1)->yield($mode, $cursorOrientation, $cursorOffset);
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-27