samayo/styrofoam

A tiny pdo wrapper class

2.0.0 2015-06-07 20:19 UTC

This package is auto-updated.

Last update: 2024-10-16 09:12:30 UTC


README

A tiny PDO wrapper class, for simple CRUD operation.

Install

Using composer

$ composer require samayo/styrofoam:1.0.*

Using git

$ git clone https://github.com/samayo/styrofoam.git

Usage

require 'path/to/styrofoam.php';

$db = new Styrofoam\Database(
  'mysql:host=localhost; dbname=db-name;  charset=utf8', 'db-user', 'db-pass', [
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC 
]);

Examples

SELECT

// returns $select with value of query
$select = $db->select('SELECT * FROM users WHERE id = ?', [145]);

INSERT

// returns value lastInsertId() on success
$insert = $db->insert('INSERT INTO users (lastname) VALUES (?)', ['robin']);

DELETE

// returns $delete as boolean
$delete = $db->delete('DELETE FROM users WHERE id = ?', [456]);

UPDATE

// returns $update as boolean
$update = $db->update('UPDATE cars SET color = ? WHERE model = ?', ['blue', 'Toyota']);