faapz/pdo

Just another PDO database library

Maintainers

👁 FaaPz
👁 kwhat

Package info

github.com/FaaPz/PDO

Documentation

pkg:composer/faapz/pdo

Statistics

Installs: 139 972

Dependents: 5

Suggesters: 0

Stars: 314

Open Issues: 6

v2.2.3 2025-04-11 18:14 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT df6663071257409fb7d1766c8a41c17e377ceea2

databasesqlpdo


README

👁 Latest Stable Version
👁 Total Downloads
👁 Latest Unstable Version
👁 License

Just another PDO database library

Installation

Use Composer

$ composer require faapz/pdo 

Usage

Examples selecting, inserting, updating and deleting data from or into 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';

$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

Changelog

See CHANGELOG

License

See LICENSE