phpgt / database
数据库API组织。
v1.6.1
2024-02-10 18:18 UTC
Requires
- php: >=8.1
- ext-pdo: *
- greenlion/php-sql-parser: ^4.6
- phpgt/cli: ^1.3
- phpgt/config: ^v1.1.0
Requires (Dev)
- ext-sqlite3: *
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^v1.10
- phpunit/phpunit: ^10.1
- squizlabs/php_codesniffer: ^3.7
- dev-master
- v1.6.1
- v1.6.0
- v1.5.0
- v1.4.1
- v1.4.0
- 1.3.0
- v1.2.0
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0.0
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.0
- v0.3.1
- v0.3.0
- v0.2.0
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.3
- v0.0.2
- v0.0.1
- dev-consistent-tests
- dev-dependabot/composer/phpunit/phpunit-9.6.4
This package is auto-updated.
Last update: 2024-09-17 12:01:22 UTC
README
数据库API组织。
将您的应用程序数据库脚本封装在简单且标准化的接口中,将数据库访问与应用程序逻辑分离。
任何数据库函数的第一个参数始终是查询名称,它表示磁盘上的一个查询文件——可以是原始SQL文件或使用SqlBuilder表示的查询的PHP表示。
示例用法
此库通过一致的API组织SQL访问。要执行位于 src/query/user/getById.sql
的示例查询,使用以下模式
$userRow = $db->fetch("user/getById", 105);
CRUD操作示例
// "fetchAll" method returns an iterable ResultSet of Row objects. $bookResultSet = $db->fetchAll("shopitem/getItemsInCategory", "books"); foreach($bookResultSet as $bookRow) { echo "Book title: ", $bookRow->getString("title"), PHP_EOL; echo "Book price: £", ($bookRow->getFloat("price") + $bookRow->getFloat("vat")), PHP_EOL; if($bookRow->offerEnds) { echo "Item on offer until: ", $bookRow->getDateTime("offerEnds")->format("dS M Y"); } } // "Create" method always returns the last inserted ID: $newCustomerId = $db->create("customer/new", [ "first_name" => "Marissa", "last_name" => "Mayer", "dob" => new DateTime("1975-05-30"), ]); // "Update" or "delete" methods always return the number of affected rows: $numberOfItemsAffected = $db->update("shop/item/increasePrice", [ "percent" => 12.5, "max_increase" => 20.00, ]); $numberOfDeletedReviews = $db->delete( "remove/deleteOlderThan", new DateTime("-6 months") ); // Individual type-safe fields can be pulled from queries that return only one column: $userName = $db->fetchString("user/getUsernameById", 105);