Framy tries to make database interaction very simple across a variety of database beckends using either raw SQL or the query builder that will soon be added.
After configuring an connection. Simply create a Instance of the DatabaseManager, no arguments neede if default (or only) configured connection should be used.
Once you configured your database connection, you may run queries using the DB class. The DB class provides methods for each type of query: select
, update
, insert
and delete
.
To run a basic query, you may use the select method on the DB class.
$user = DB::select("select * from users where id=:id", ['id'=>12]);
To execute an insert statement, you may use the insert method on the DB class.
DB::insert("insert into user (username, password) VALUES [...] ");
The update method should be used to update existing records in the database. The number of rows affected by the statement will be returned:
$affected = DB::update('update users set votes = 100 where name = ?', ['John']);
The delete method should be used to delete records from the database. Like update, the number of rows affected will be returned:
$deleted = DB::delete('delete from users');