Skip to content

samayo/styrofoam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

Styrofoam

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