Skip to content
Just another PDO database library
Branch: 2.x
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
src Rename package namespace in favor of Slim Framework Mar 6, 2019
tests Some preparations and minor fixes May 29, 2016
.gitattributes Release version 1.9.0 Nov 30, 2015
.gitignore Some preparations and minor fixes May 29, 2016
CHANGELOG.md
LICENSE
README.md
composer.json Rename package namespace in favor of Slim Framework Mar 6, 2019

README.md

PDO

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';

$pdo = new \FaaPz\PDO\Database($dsn, $usr, $pwd);

// SELECT * FROM users WHERE id = ?
$selectStatement = $pdo->select()
                       ->from('users')
                       ->where('id', '=', 1234);

$stmt = $selectStatement->execute();
$data = $stmt->fetch();

// INSERT INTO users ( id , usr , pwd ) VALUES ( ? , ? , ? )
$insertStatement = $pdo->insert(array(
                           "id" =>1234,
                           "usr" => "your_username",
                           "pwd" => "your_password"
                       ))
                       ->into("users");

$insertId = $insertStatement->execute();

// UPDATE users SET pwd = ? WHERE id = ?
$updateStatement = $pdo->update(array("pwd" => "your_new_password"))
                       ->table("users")
                       ->where(new Clause\Conditional("id", "=", 1234));

$affectedRows = $updateStatement->execute();

// DELETE FROM users WHERE id = ?
$deleteStatement = $pdo->delete()
                       ->from("users")
                       ->where(new Clause\Conditional("id", "=", 1234));

$affectedRows = $deleteStatement->execute();

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

You can’t perform that action at this time.