dbFacile v0.4

Started: 2006-08-10 Updated: 2008-02-29
Progress: 95%
Language: PHP5
OS: Web
License: MIT

Browse the Latest Code

This project used to be called dbSimple, but I've changed it's name to avoid confusion with this project.

A PHP Database Abstraction Class that honestly offers a simpler interface than all known alternatives. It is intended to have the best combination of simplicity and usability. I've also created a PHP Database Abstraction Class Comparison to show where dbFacile stands.

Features

Driving Ideals

  1. Inserts and Updates are trivial and thus should be automated
  2. Traditional prepared statements are rarely worth their trouble
  3. Access to fields should be done by name and not column index, because, if your CREATE TABLE statement is modified, the index might pertain to a different field
  4. The most common operations (SELECTs) shouldn't take more than 1 line of code, and should return a data structure native to PHP for ease

Why Not Use ... ?

Standard PHP API Functions

Pear MDB2

PDO

ADODb

Others

Upcoming Features

 

Download

Mercurial Repository

Here - Keep up

0.4

Not released yet. Check the repository above.

0.3

Note: There is 1 known issue with this release. The fetchKeyValue() method has a bug. I will be fixed in the next release but for now you can change line 227 to: $data[ $key ] = array_shift($row);

CHANGES and README

dbFacile-0.3.tar.gz

dbFacile-0.3.zip

0.2.1

Connecting to a database has changed in this version. Check the README for proper usage. Other changes include: MIT license, split DB-specific code into "driver classes", safer way to specify where clause for update() that prevents SQL injection, and more.

dbFacile-0.2.1.tar.gz

dbFacile-0.2.1.zip

Agenda

Full functionality for Microsoft SQL Server and Sqlite3 is in the works. Basic fetching methods work, but more advanced things like inserts and updates might be broken in places.

Methods

See the README for better examples

dbFacile_mysql([connection handle])
Pass in existing connection handle to use it. (Eliminates need to call open())
open(USERNAME, PASSWORD, DATABASE, HOST)
Connects to database
logToFile(FILE)
Logs all queries to a file
fetch('select * from users')
Performs SQL query and returns two-dimensional array of rows and each's columns and values.
fetchRow('select * from users where name=?','john')
Performs SQL query and returns associative array of fields and values.
fetchCell(SQL)
Performs SQL query and returns first field from first row in result.
fetchColumn(SQL)
Performs SQL and returns the first column as a 1-dimensional array.
fetchKeyValue(SQL)
Performs SQL and returns an associative array with users.id as the key and users.email as the value for each. If more than two fields are fetched, the first field is used as the key and an array of the remaining fields becomes the value.
insert(DATA, TABLE)
Inserts associative array of data into table, returns newly generated primary key. Associative array keys should correspond to the table's field names.
update(DATA, TABLE, WHERE)
Updates records in table with associative array of data satisfying where clause. Returns number of affected rows. See insert() above.
delete(TABLE, WHERE)
Deletes records in table satisfying the where clause. WHERE is optional.
beginTransaction()
Begins a transaction
commitTransaction()
Commits a transaction
rollbackTransaction()
Rolls back a transaction

 

This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 Unported License.