jasny / db-mysql
A simple DB layer in PHP for using MySQL
Installs: 1 234
Dependents: 1
Suggesters: 0
Security: 0
Stars: 14
Watchers: 1
Forks: 4
Open Issues: 2
Requires
- php: >=5.3.0
Suggests
- jasny/config: Configure your DB and make it work out of the box
- jasny/dbquery-mysql: Supports building, parsing and modifying MySQL queries
This package is auto-updated.
Last update: 2020-09-11 11:05:46 UTC
README
A simple DB layer in PHP for using MySQL, featuring
- Global connection (singleton)
- Parameter binding
- Quoting tables/fields and values
- Fetch all rows, column, key/value pair and single value
- Simple saving by passing associated arrays
- Query exceptions (instead of returning false)
Installation
Jasny DB-MySQL is registred at packagist as jasny/db-mysql and can be easily installed using composer. Alternatively you can simply download the .zip and copy the file from the 'src' folder.
Example
<?php
new DB($host, $user, $pwd, $dbname);
$result = DB::conn()->query("SELECT * FROM foo");
$result = DB::conn()->query("SELECT * FROM foo WHERE type = ?", $type);
$result = DB::conn()->query("SELECT * FROM foo WHERE type = ? AND cat IN ?", $type, array(1, 7));
$items = DB::conn()->fetchAll("SELECT id, name, description FROM foo WHERE type = ?", MYSQLI_ASSOC, $type);
$item = DB::conn()->fetchOne("SELECT * FROM foo WHERE id = ?", MYSQLI_ASSOC, $id);
$names = DB::conn()->fetchColumn("SELECT name FROM foo WHERE type = ?", $type);
$list = DB::conn()->fetchPairs("SELECT id, name FROM foo WHERE type = ?", $type);
$name = DB::conn()->fetchValue("SELECT name FROM foo WHERE id = ?", $id);
DB::conn()->save('foo', $values);
DB::conn()->save('foo', array($values1, $values2, $values3));