{"id":15295216,"url":"https://github.com/tbreuss/pdo","last_synced_at":"2026-01-04T08:16:47.602Z","repository":{"id":218341367,"uuid":"745505984","full_name":"tbreuss/pdo","owner":"tbreuss","description":"A thin wrapper for the native PDO extension with additional functionality.","archived":false,"fork":false,"pushed_at":"2025-01-07T18:48:23.000Z","size":13847,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T06:51:20.597Z","etag":null,"topics":["database","pdo","pdo-instance","pdo-php","pdo-wrapper","php","php-pdo"],"latest_commit_sha":null,"homepage":"https://github.com/tbreuss/pdo","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tbreuss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-19T13:36:50.000Z","updated_at":"2025-01-07T18:47:44.000Z","dependencies_parsed_at":"2024-02-05T08:24:47.267Z","dependency_job_id":"404f9a0e-389c-4af0-851e-30de540dc3a4","html_url":"https://github.com/tbreuss/pdo","commit_stats":null,"previous_names":["tbreuss/pdox","tbreuss/xpdo"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbreuss%2Fpdo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbreuss%2Fpdo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbreuss%2Fpdo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbreuss%2Fpdo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tbreuss","download_url":"https://codeload.github.com/tbreuss/pdo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248741196,"owners_count":21154252,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","pdo","pdo-instance","pdo-php","pdo-wrapper","php","php-pdo"],"created_at":"2024-09-30T17:09:04.417Z","updated_at":"2026-01-04T08:16:47.572Z","avatar_url":"https://github.com/tbreuss.png","language":"PHP","readme":"[![PHP Version Require](http://poser.pugx.org/tebe/pdo/require/php)](https://packagist.org/packages/tebe/pdo)\n[![Version](http://poser.pugx.org/tebe/pdo/version)](https://packagist.org/packages/tebe/pdo)\n[![Testing tebe\\pdo](https://github.com/tbreuss/pdo/actions/workflows/tests.yml/badge.svg)](https://github.com/tbreuss/pdo/actions/workflows/tests.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n# tebe\\pdo\n\nProvides an extension to the native PDO along with additional functionality.\n\n`tebe\\pdo` is an extension of the native PDO in the style of a thin wrapper. All constants, properties and methods of the underlying PDO classes are therefore available. Code already using or typehinted to the native PDO can use `tebe\\pdo` with minimal changes for the most part.\n\nAdded or changed functionality in `tebe\\pdo` over the native PDO includes:\n\n- Exceptions by default. `tebe\\pdo` starts in the ERRMODE_EXCEPTION mode for error reporting instead of the ERRMODE_SILENT mode.\n- New `PDO::run()` method. This is for convenience to prepare and execute an SQL statement in one step.\n- Bind array of values to placeholder in `PDO::run()` method. Placeholders that represent array values will be replaced with comma-separated quoted values. This means you can bind an array of values to a placeholder used with an IN (...) condition.\n- Array quoting. The `PDO::quote()` method will accept an array as input, and return a string of comma-separated quoted values.\n- New `PDOStatement::fetch*()` methods. The new methods provide for commonly-used fetch actions.\n- New `PDOStatement::fetchAll*()` methods. The new methods provide for commonly-used fetch all actions.\n\n## Examples\n\nCreate a PDO instance representing a connection to a database.\n\n```php\nuse tebe\\pdo\\PDO;\n$db = new PDO('sqlite:database.sqlite');\n```\n\nExecute an SQL statement without placeholders and return the number of affected rows.\n\n```php\n$sql = \"INSERT INTO fruits VALUES\n(1, 'Banana', 'yellow', 250),\n(2, 'Apple', 'red', 150),\n(3, 'Pear', 'green', 150),\n(4, 'Orange', 'orange', 300),\n(5, 'Lime', 'green', 333),\n(6, 'Lemon', 'yellow', 25),\n(7, 'Peach', 'orange', 100),\n(8, 'Cherry', 'red', 200)\";\nprint $db-\u003eexec($sql);\n// outputs 8\n```\n\nPrepare and execute an SQL statement without placeholders, and fetch all rows from the result set.\n\n```php\n$sql = \"SELECT name, color FROM fruits WHERE color = 'green' ORDER BY name\";\nprint json_encode($db-\u003equery($sql)-\u003efetchAll());\n// outputs [{\"name\":\"Lime\",\"color\":\"green\"},{\"name\":\"Pear\",\"color\":\"green\"}]\n```\n\nPrepare a statement with placeholders for execution, return a statement object, and fetch all columns from the result set.\n\n```php\n$sql = \"SELECT name FROM fruits WHERE color = ? ORDER BY name\";\nprint json_encode($db-\u003eprepare($sql)-\u003eexecute(['red'])-\u003efetchAllColumn());\n// outputs [\"Apple\",\"Cherry\"]\n```\n\nRun a query with placeholders, return the resulting PDOStatement, and fetch key value array (pairs) from the result set.\n\n```php\n$sql = \"SELECT name, calories FROM fruits WHERE color = ? ORDER BY name\";\nprint json_encode($db-\u003erun($sql, ['red'])-\u003efetchAllPair());\n// outputs {\"Banana\":250,\"Lemon\":25}\n```\n\nRun a query with an IN clause and placeholders, return the resulting PDOStatement, and fetch all rows grouped by color from the result set.\n\n```php\n$sql = \"SELECT color, name FROM fruits WHERE color IN (?) ORDER BY name\";\nprint json_encode($db-\u003erun($sql, [['green', 'red']])-\u003efetchAllGroup());\n// outputs {\"red\":[{\"name\":\"Apple\"},{\"name\":\"Cherry\"}],\"green\":[{\"name\":\"Lime\"},{\"name\":\"Pear\"}]}\n```\n\nQuote an array for use in a query.\n\n```php\nprint $db-\u003equote(['red', 'green', 'yellow']);\n// outputs 'red', 'green', 'yellow'\n```\n\n## Installation and Autoloading\n\nThis package is installable and PSR-4 autoloadable via Composer as `tebe/pdo`.\n\nAlternatively, download a release, or clone this repository, then include the classes manually:\n\n```php\ninclude '{path/to/tebe/pdo}/src/PDO.php';\ninclude '{path/to/tebe/pdo}/src/PDOStatement.php';\ninclude '{path/to/tebe/pdo}/src/PDOParser.php';\n```\n\n## Dependencies\n\nThis package requires PHP 8.2 or later; it has been tested on latest Linux, macOS and Windows on PHP 8.2-8.6. We recommend using the latest available version of PHP as a matter of principle. `tebe\\pdo` doesn't depend on other external packages.\n\n## Documentation\n\n### tebe\\pdo\\PDO\n\nThe class `tebe\\pdo\\PDO` is a wrapper for the native `PDO` class and implements all methods of this class. \n\nThe main differences are that some methods return `tebe\\pdo\\PDOStatement` instances and the `quote` method can also handle arrays.\n\nIn addition, the class contains a new method `run`, which executes a query with bound values and returns the resulting statement instance.\n\n#### getWrappedPdo\n\nReturns the underlying PDO instance.\n\n```php\npublic PDO::getWrappedPdo(): \\PDO\n```\n\n#### prepare\n\nPrepares a statement for execution and returns a statement object.\n\nThis differs from `PDO::prepare` in that it will return a `tebe\\pdo\\PDOStatement` object.\n\n```php\npublic PDO::prepare(string $query, array $options = []): PDOStatement|false\n```\n\nSee [php.net](https://php.net/pdo.prepare)\n\n#### query\n\nPrepares and executes an SQL statement without placeholders.\n\nThis differs from `PDO::query` in that it will return a `tebe\\pdo\\PDOStatement` object.\n\n```php\npublic PDO::query(string $query, mixed ...$fetchModeArgs): PDOStatement|false\n```\n\nSee [php.net](https://php.net/pdo.query)\n\n#### quote\n\nQuotes a string for use in a query.\n\nThis differs from `PDO::quote` in that it will convert an array into a string of comma-separated quoted values.\n\n```php\npublic PDO::quote(array|string|int|float|null $value, int $type = PDO::PARAM_STR): string|false\n```\n\nSee [php.net](https://php.net/pdo.quote)\n\n#### run\n\nRuns a query with bound values and returns the resulting `tebe\\pdo\\PDOStatement`. \n\nArray values will be processed by the parser instance and placeholders are replaced.\n\n```php\npublic PDO::run(string $sql, ?array $args = null): PDOStatement|false\n```\n\n---\n\nThe remaining `tebe\\pdo\\PDO` methods are simple wrapper methods of the underlying `PDO` class.\nFor more information, see [php.net](https://php.net/pdo).\n\n- [beginTransaction](https://php.net/pdo.beginTransaction)\n- [commit](https://php.net/pdo.commit)\n- [__construct](https://php.net/pdo.__construct)\n- [errorCode](https://php.net/pdo.errorCode)\n- [errorInfo](https://php.net/pdo.errorInfo)\n- [exec](https://php.net/pdo.exec)\n- [getAttribute](https://php.net/pdo.getAttribute)\n- [getAvailableDrivers](https://php.net/pdo.getAvailableDrivers)\n- [inTransaction](https://php.net/pdo.inTransaction)\n- [lastInsertId](https://php.net/pdo.lastInsertId)\n- [rollBack](https://php.net/pdo.rollBack)\n- [setAttribute](https://php.net/pdo.setAttribute)\n\n### tebe\\pdo\\PDOStatement\n\nThe class `tebe\\pdo\\PDOStatement` is a wrapper for the native `PDOStatement` class and implements all methods of this class. \n\nThe main difference is that the `execute` method returns a statement instance. This was done to allow method chaining aka fluent interface.\n\nBesides that it contains several new `fetch*()` and `fetchAll*()` methodes for commonly-used fetch actions.\n\n#### __construct\n\nCreates a `tebe\\pdo\\PDOStatement` instance representing a query statement and wraps the original `PDOStatement`.\n\n```php\npublic PDOStatement::__construct(\\PDOStatement $stmt)\n```\n\n#### execute\n\nExecutes a prepared statement\n\nThis differs from `PDOStatement::execute` in that it will return a `tebe\\pdo\\PDOStatement` object.\n\n```php\npublic PDOStatement::execute(?array $params = null): PDOStatement|false\n```\n\nSee [php.net](https://php.net/pdostatement.execute)\n\n#### fetchAffected\n\nFetches the number of affected rows from the result set.\n\n```php\npublic PDOStatement::fetchAffected(): int\n```\n\n#### fetchAssoc\n\nFetches the next row from the result set as an associative array.\n\n```php\npublic PDOStatement::fetchAssoc(): array|false\n```\n\n#### fetchBoth\n\nFetches the next row from the result set as an associative and indexed array.\n\n```php\npublic PDOStatement::fetchBoth(): array|false\n```\n\n#### fetchInto\n\nFetches the next row from the result as the updated passed object, by mapping the columns to named properties of the object.\n\n```php\npublic PDOStatement::fetchInto(object $object): object|false\n```\n\n#### fetchNamed\n\nFetches the next row from the result set as an associative array;\nIf the result set contains multiple columns with the same name, an array of values per column name is returned.\n\n```php\npublic PDOStatement::fetchNamed(): array|false\n```\n\n#### fetchNumeric\n\nFetches the next row from the result set as an indexed array.\n\n```php\npublic PDOStatement::fetchNumeric(): array|false\n```\n\n#### fetchPair\n\nFetches the next row from the result set as a key-value pair.\n\n```php\npublic PDOStatement::fetchPair(): array|false\n```\n\n#### fetchAllAssoc\n\nFetches all rows from the result set as an array of associative arrays.\n\n```php\npublic PDOStatement::fetchAllAssoc(): array\n```\n\n#### fetchAllBoth\n\nFetches all rows from the result set as an array of associative and indexed arrays.\n\n```php\npublic PDOStatement::fetchAllBoth(): array\n```\n\n#### fetchAllColumn\n\nFetches all rows from the result set as an array of a single column.\n\n```php\npublic PDOStatement::fetchAllColumn(int $column = 0): array\n```\n\n#### fetchAllFunction\n\nFetches all rows from the result set as an array by calling a function for each row.\n\n```php\npublic PDOStatement::fetchAllFunction(callable $callable): array\n```\n\n#### fetchAllGroup\n\nFetches all rows from the result set as an array by grouping all rows by a single column.\n\n```php\npublic PDOStatement::fetchAllGroup(int $style = 0): array\n```\n\n#### fetchAllNamed\n\nFetches all rows from the result set as an array of associative arrays;\nIf the result set contains multiple columns with the same name, an array of values per column name is returned.\n\n```php\npublic PDOStatement::fetchAllNamed(): array\n```\n\n#### fetchAllNumeric\n\nFetches all rows from the result set as an array of indexed arrays.\n\n```php\npublic PDOStatement::fetchAllNumeric(): array\n```\n\n#### fetchAllObject\n\nFetches all rows from the result set as an array of objects of the requested class, \nmapping the columns to named properties in the class.\n\n```php\npublic PDOStatement::fetchAllObject(string $class = 'stdClass', ?array $constructorArgs = null, int $style = 0): array\n```\n\n#### fetchAllPair\n\nFetches all rows from the result set as an array of key-value pairs.\n\n```php\npublic PDOStatement::fetchAllPair(): array\n```\n\n#### fetchAllUnique\n\nFetches all rows from the result set as an array of arrays, indexed by an unique field.\n\n```php\npublic PDOStatement::fetchAllUnique(int $style = 0): array\n```\n\n---\n\nThe remaining `tebe\\pdo\\PDOStatement` methods are simple wrapper methods of the underlying `PDOStatement` class.\nFor more information, see [php.net](https://php.net/pdostatement).\n\n- [bindColumn](https://php.net/pdostatement.bindcolumn)\n- [bindParam](https://php.net/pdostatement.bindParam)\n- [bindValue](https://php.net/pdostatement.bindValue)\n- [closeCursor](https://php.net/pdostatement.closeCursor)\n- [columnCount](https://php.net/pdostatement.columnCount)\n- [debugDumpParams](https://php.net/pdostatement.debugDumpParams)\n- [errorCode](https://php.net/pdostatement.errorCode)\n- [errorInfo](https://php.net/pdostatement.errorInfo)\n- [fetch](https://php.net/pdostatement.fetch)\n- [fetchAll](https://php.net/pdostatement.fetchAll)\n- [fetchColumn](https://php.net/pdostatement.fetchColumn)\n- [fetchObject](https://php.net/pdostatement.fetchObject)\n- [getAttribute](https://php.net/pdostatement.getAttribute)\n- [getColumnMeta](https://php.net/pdostatement.getColumnMeta)\n- [getIterator](https://php.net/pdostatement.getIterator)\n- [nextRowset](https://php.net/pdostatement.nextRowset)\n- [rowCount](https://php.net/pdostatement.rowCount)\n- [setAttribute](https://php.net/pdostatement.setAttribute)\n- [setFetchMode](https://php.net/pdostatement.setFetchMode)\n\n### tebe\\pdo\\PDOParser\n\nClass `tebe\\pdo\\PDOParser` offers parsing and rebuilding functions for all drivers.\n\n#### __construct\n\nCreates a `tebe\\pdo\\PDOParser` instance.\n\n```php\npublic PDOParser::__construct(string $driver)\n```\n\n#### rebuild\n\nRebuilds a statement with placeholders and bound values.\n\n```php\npublic PDOParser::rebuild(string $statement, array $values = []): array\n```\n\n## Quality\n\n[![Testing tebe\\pdo](https://github.com/tbreuss/pdo/actions/workflows/tests.yml/badge.svg)](https://github.com/tbreuss/pdo/actions/workflows/tests.yml)\n\nThis project adheres to [Semantic Versioning](https://semver.org/).\n\nTo run the functional tests at the command line, issue `composer install` and then `composer test` at the package root. (This requires [Composer](https://getcomposer.org/) to be available as `composer`.)\n\nThis package attempts to comply with [PSR-1](https://www.php-fig.org/psr/psr-1/), [PSR-4](https://www.php-fig.org/psr/psr-4/), and [PSR-12](https://www.php-fig.org/psr/psr-12/). If you notice compliance oversights, please send a patch via pull request.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbreuss%2Fpdo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftbreuss%2Fpdo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbreuss%2Fpdo/lists"}