particlebits / pdo
Smallest possible PDO database while being super useful
2.1.4
2022-04-07 22:46 UTC
Requires
- php: >= 5.6
- ext-pdo: *
README
Micro PDO Library
Smallest possible PDO database while still being super useful
Installation
Use Composer
"require": { "ParticleBits/pdo": "~2.0" }
Features
- Compatible with PHP 5.6 and higher!
- Tested on all versions of PHP 5.6 -> 7.4 (Not tested yet on PHP 8.x)
- No dependencies other than the PDO extension
- Tiny footprint
Usage
Examples selecting, inserting, updating and deleting data from or into the users
table.
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'; $pdo = new \Pb\PDO\Database($dsn, $usr, $pwd); // SELECT * FROM users WHERE id = ? $stmt = $pdo ->select() ->from('users') ->where('id', '=', 1234) ->execute(); $data = $stmt->fetch(); // INSERT INTO users (id , usr , pwd) VALUES (? , ? , ?) $stmt = $pdo ->insert(['id', 'usr', 'pwd']) ->into('users') ->values([1234, 'your_username', 'your_password']); $insertId = $stmt->execute(true); // true returns insert ID // UPDATE users SET pwd = ? WHERE id = ? $stmt = $pdo ->update(['pwd' => 'your_new_password']) ->table('users') ->where('id', '=', 1234); $affectedRows = $stmt->execute(); // DELETE FROM users WHERE id = ? $stmt = $pdo ->delete() ->from('users') ->where('id', '=', 1234); $affectedRows = $stmt->execute();
Notes on the sqlsrv
extension
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
Changelog
See CHANGELOG
License
See LICENSE