Querying

From RedBean

Jump to: navigation, search

Querying

To perform a query, get a database adapter and :

$database->exec( "update page set title='test' where id=1" );

To fetch a multidimensional resultset directly after firing the query:

$database->get( "select * from page" );

To fetch a single row:

$database->getRow("select * from page limit 1");

To fetch a single column:

$database->getCol("select title from page");

To fetch a single cell:

$database->getCell("select title from page limit 1");

To get the latest insert-id:

$database->getInsertID();

To get the number of rows affected:

$database->getAffectedRows();

To escape a value or columname for use in custom SQL use:

$database->escape( $value );

To get the original result resource to do your own processing:

$database->getRaw();

Transactions

From RedBean 0.7.8 on you can use transactions:

To start a transaction:

$database->startTransaction();

To commit:

$database->commit();

And finally, to roll back a transaction:

$database->rollback();
Personal tools