GithubHelp home page GithubHelp logo

pdo's Introduction

\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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.