\RedBeanPHP\AdapterDBAdapter

DBAdapter (Database Adapter)

An adapter class to connect various database systems to RedBean Database Adapter Class. The task of the database adapter class is to communicate with the database driver. You can use all sorts of database drivers with RedBeanPHP. The default database drivers that ships with the RedBeanPHP library is the RPDO driver ( which uses the PHP Data Objects Architecture aka PDO ).

Summary

Methods
Properties
Constants
addEventListener()
signal()
__construct()
getSQL()
exec()
get()
getRow()
getCol()
getAssoc()
getAssocRow()
getCell()
getCursor()
getInsertID()
getAffectedRows()
getDatabase()
startTransaction()
commit()
rollback()
close()
setInitCode()
setOption()
getDatabaseServerVersion()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$observers
$db
$sql
N/A

Properties

$observers

$observers : array

Type

array

$sql

$sql : string

Type

string

Methods

addEventListener()

addEventListener(string  $eventname, \RedBeanPHP\Observer  $observer) : void

Implementation of the Observer Pattern.

Adds an event listener to the observable object. First argument should be the name of the event you wish to listen for. Second argument should be the object that wants to be notified in case the event occurs.

Parameters

string $eventname

event identifier

\RedBeanPHP\Observer $observer

observer instance

signal()

signal(string  $eventname, mixed  $info) : void

Notifies listeners.

Sends the signal $eventname, the event identifier and a message object to all observers that have been registered to receive notification for this event. Part of the observer pattern implementation in RedBeanPHP.

Parameters

string $eventname

event you want signal

mixed $info

message object to send along

__construct()

__construct(\RedBeanPHP\Driver  $database) 

Constructor.

Creates an instance of the RedBean Adapter Class. This class provides an interface for RedBean to work with ADO compatible DB instances.

Usage:

$database = new RPDO( $dsn, $user, $pass ); $adapter = new DBAdapter( $database ); $writer = new PostgresWriter( $adapter ); $oodb = new OODB( $writer, FALSE ); $bean = $oodb->dispense( 'bean' ); $bean->name = 'coffeeBean'; $id = $oodb->store( $bean ); $bean = $oodb->load( 'bean', $id );

The example above creates the 3 RedBeanPHP core objects: the Adapter, the Query Writer and the OODB instance and wires them together. The example also demonstrates some of the methods that can be used with OODB, as you see, they closely resemble their facade counterparts.

The wiring process: create an RPDO instance using your database connection parameters. Create a database adapter from the RPDO object and pass that to the constructor of the writer. Next, create an OODB instance from the writer. Now you have an OODB object.

Parameters

\RedBeanPHP\Driver $database

ADO Compatible DB Instance

getSQL()

getSQL() : string

Returns a string containing the most recent SQL query processed by the database adapter, thus conforming to the interface:

Returns

string

exec()

exec(string  $sql, array  $bindings = array(), boolean  $noevent = FALSE) : integer

Executes an SQL Statement using an array of values to bind If $noevent is TRUE then this function will not signal its observers to notify about the SQL execution; this to prevent infinite recursion when using observers.

Parameters

string $sql

string containing SQL code for database

array $bindings

array of values to bind to parameters in query string

boolean $noevent

no event firing

Returns

integer

get()

get(string  $sql, array  $bindings = array()) : array

Executes an SQL Query and returns a resultset.

This method returns a multi dimensional resultset similar to getAll The values array can be used to bind values to the place holders in the SQL query.

Parameters

string $sql

string containing SQL code for database

array $bindings

array of values to bind to parameters in query string

Returns

array

getRow()

getRow(string  $sql, array  $bindings = array()) : array|NULL

Executes an SQL Query and returns a resultset.

This method returns a single row (one array) resultset. The values array can be used to bind values to the place holders in the SQL query.

Parameters

string $sql

string containing SQL code for database

array $bindings

array of values to bind to parameters in query string

Returns

array|NULL

getCol()

getCol(string  $sql, array  $bindings = array()) : array

Executes an SQL Query and returns a resultset.

This method returns a single column (one array) resultset. The values array can be used to bind values to the place holders in the SQL query.

Parameters

string $sql

string containing SQL code for database

array $bindings

array of values to bind to parameters in query string

Returns

array

getAssoc()

getAssoc(string  $sql, array  $bindings = array()) : array

Executes the SQL query specified in $sql and indexes the row by the first column.

Parameters

string $sql

string containing SQL code for database

array $bindings

array of values to bind to parameters in query string

Returns

array

getAssocRow()

getAssocRow(string  $sql, array  $bindings = array()) : array

Executes the SQL query specified in $sql and returns an associative array where the column names are the keys.

Parameters

string $sql

String containing SQL code for databaseQL

array $bindings

values to bind

Returns

array

getCell()

getCell(string  $sql, array  $bindings = array(),   $noSignal = NULL) : string|NULL

Executes an SQL Query and returns a resultset.

This method returns a single cell, a scalar value as the resultset. The values array can be used to bind values to the place holders in the SQL query.

Parameters

string $sql

string containing SQL code for database

array $bindings

array of values to bind to parameters in query string

$noSignal

Returns

string|NULL

getCursor()

getCursor(string  $sql, array  $bindings = array()) : \RedBeanPHP\Cursor

Returns a database agnostic Cursor object.

Parameters

string $sql

string containing SQL code for database

array $bindings

array of values to bind to parameters in query string

Returns

\RedBeanPHP\Cursor

getInsertID()

getInsertID() : integer

Returns the latest insert ID.

Returns

integer

getAffectedRows()

getAffectedRows() : integer

Returns the number of rows that have been affected by the last update statement.

Returns

integer

getDatabase()

getDatabase() : \RedBeanPHP\Driver

Returns the original database resource. This is useful if you want to perform operations on the driver directly instead of working with the adapter. RedBean will only access the adapter and never to talk directly to the driver though.

Returns

\RedBeanPHP\Driver

startTransaction()

startTransaction() : void

This method is part of the RedBean Transaction Management mechanisms.

Starts a transaction.

commit()

commit() : void

This method is part of the RedBean Transaction Management mechanisms.

Commits the transaction.

rollback()

rollback() : void

This method is part of the RedBean Transaction Management mechanisms.

Rolls back the transaction.

close()

close() : void

Closes database connection.

setInitCode()

setInitCode(callable  $code) 

Sets initialization code for connection.

Parameters

callable $code

setOption()

setOption(string  $optionKey, string  $optionValue) : boolean

Sets a driver specific option.

Using this method you can access driver-specific functions. If the selected option exists the value will be passed and this method will return boolean TRUE, otherwise it will return boolean FALSE.

Parameters

string $optionKey

option key

string $optionValue

option value

Returns

boolean

getDatabaseServerVersion()

getDatabaseServerVersion() : string

Returns the version string from the database server.

Returns

string