https://github.com/faapz/pdo
Just another PDO database library
https://github.com/faapz/pdo
pdo pdo-database-library php-library php72 query-builder
Last synced: 2 months ago
JSON representation
Just another PDO database library
- Host: GitHub
- URL: https://github.com/faapz/pdo
- Owner: FaaPz
- License: mit
- Created: 2015-07-25T17:03:00.000Z (almost 10 years ago)
- Default Branch: 2.x
- Last Pushed: 2025-04-03T05:09:51.000Z (2 months ago)
- Last Synced: 2025-04-08T12:07:58.431Z (2 months ago)
- Topics: pdo, pdo-database-library, php-library, php72, query-builder
- Language: PHP
- Homepage:
- Size: 287 KB
- Stars: 315
- Watchers: 22
- Forks: 102
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PDO
[](https://packagist.org/packages/faapz/pdo)
[](https://packagist.org/packages/faapz/pdo)
[](https://packagist.org/packages/faapz/pdo)
[](https://packagist.org/packages/faapz/pdo)Just another PDO database library
### Installation
Use [Composer](https://getcomposer.org/)
```bash
$ composer require faapz/pdo
```### Usage
Examples selecting, inserting, updating and deleting data from or into `users` table.
```php
require_once 'vendor/autoload.php';$dsn = 'mysql:host=your_db_host;dbname=your_db_name;charset=utf8';
$usr = 'your_db_username';
$pwd = 'your_db_password';$database = new FaaPz\PDO\Database($dsn, $usr, $pwd);
// SELECT * FROM users WHERE id = ?
$select = $database->select()
->from('users')
->where(new FaaPz\PDO\Clause\Conditional('id', '=', 1234));if ($insert->execute()) {
$data = $stmt->fetch();
}// INSERT INTO users (id , username , password) VALUES (? , ? , ?)
$insert = $database->insert(
'id',
'username',
'password'
)
->into('users')
->values(
1234,
'user',
'passwd'
);if ($insert->execute()) {
$insertId = $database->lastInsertId();
}// UPDATE users SET pwd = ? WHERE id = ?
$update = $database->update(["pwd" => "your_new_password"])
->table("users")
->where(new FaaPz\PDO\Clause\Conditional("id", "=", 1234));if (($result = $update->execute()) !== false) {
$affectedRows = $result->rowCount();
}// DELETE FROM users WHERE id = ?
$delete = $database->delete()
->from("users")
->where(new FaaPz\PDO\Clause\Conditional("id", "=", 1234));if (($result = $delete->execute()) !== false) {
$affectedRows = $result->rowCount();
}
```> The `sqlsrv` extension will fail to connect when using error mode `PDO::ERRMODE_EXCEPTION` (default). To connect, you will need to explicitly pass `array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING)` (or `PDO::ERRMODE_SILENT`) into the constructor, or override the `getDefaultOptions()` method when using `sqlsrv`.
### Documentation
See [DOCUMENTATION](docs/README.md)
### Changelog
See [CHANGELOG](CHANGELOG.md)
### License
See [LICENSE](LICENSE.md)