Skip to content

ParticleBits/pdo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

de1cd46 · Apr 7, 2022

History

80 Commits
Mar 31, 2022
Apr 7, 2022
Mar 31, 2022
Nov 30, 2015
Sep 16, 2018
Mar 31, 2022
Apr 7, 2022
Oct 25, 2018
Mar 31, 2022
Mar 31, 2022
Mar 31, 2022

Repository files navigation

\Pb\PDO

Micro PDO Library

Latest Stable Version License

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