PDO 封装 API
dev-master
2022-10-16 00:00 UTC
Requires
- php: >=8.1.13
- ext-pdo: *
Requires (Dev)
- friendsofphp/php-cs-fixer: dev-master
- pds/skeleton: ^1.0
This package is auto-updated.
Last update: 2024-09-17 00:49:44 UTC
README
PHP PDO 封装 API
基本用法
<?php require __DIR__ ."/../vendor/autoload.php"; $dbh = new \TorresDeveloper\PdoWrapperAPI\mysqlConnection( new Core\PDODataSourceName([ "host" => "192.168.1.40", "database" => "exampleDatabase", ], Core\Credentials::getCredentials( "user", "passwd" )) ); /* * Use the CRUD interface for easy operations: * - select; * - insert; * - update; * - delete. */ // get all from all users $dbh->select("user")->fetchAll(PDO::FETCH_OBJ); // get all users `id` $dbh->select("id", "user")->fetchAll(PDO::FETCH_OBJ); // get all users `name` and `age` $dbh->select(["name", "age"], "user")->fetchAll(PDO::FETCH_OBJ); // insert new users $users = [ ["id" => 123, "name" => "asdfs"], ["age" => 2], ["id" => null, "text" => "y7tgebh"] ]; $dbh->insert("user", ...$users); /* * You can use a query builder for more complex operations: */ $dbh->getBuider()->select() ->from("user") ->limit(5) ->run() ->fetchAll(\PDO::FETCH_OBJ)