Overview

Namespaces

  • None
  • RedBeanPHP
    • Adapter
    • BeanHelper
    • Cursor
    • Driver
    • Logger
      • RDefault
    • QueryWriter
    • RedException
    • Repository
    • Util

Classes

  • AssociationManager
  • BeanCollection
  • DuplicationManager
  • Facade
  • Finder
  • Jsonable
  • LabelMaker
  • Observable
  • OODB
  • OODBBean
  • R
  • Repository
  • SimpleModel
  • SimpleModelHelper
  • TagManager
  • ToolBox

Interfaces

  • Adapter
  • BeanHelper
  • Cursor
  • Driver
  • Logger
  • Observer
  • Plugin
  • QueryWriter

Exceptions

  • RedException
  • Overview
  • Namespace
  • Class

Class OODB

RedBean Object Oriented DataBase.

The RedBean OODB Class is the main class of RedBeanPHP. It takes OODBBean objects and stores them to and loads them from the database as well as providing other CRUD functions. This class acts as a object database.

RedBeanPHP\Observable
Extended by RedBeanPHP\OODB
Namespace: RedBeanPHP
Copyright:

copyright (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community This source file is subject to the BSD/GPLv2 License that is bundled with this source code in the file license.txt.


License: BSD/GPLv2
Author: Gabor de Mooij and the RedBeanPHP community
File: RedBeanPHP/OODB.php
Located at OODB.php
Methods summary
public static
# autoClearHistoryAfterStore( boolean $autoClear = TRUE )

If set to TRUE, this method will call clearHistory every time the bean gets stored.

If set to TRUE, this method will call clearHistory every time the bean gets stored.

Parameters

$autoClear
auto clear option
protected RedBeanPHP\OODBBean
# unboxIfNeeded( RedBeanPHP\OODBBean $bean )

Unboxes a bean from a FUSE model if needed and checks whether the bean is an instance of OODBBean.

Unboxes a bean from a FUSE model if needed and checks whether the bean is an instance of OODBBean.

Parameters

$bean
bean you wish to unbox

Returns

RedBeanPHP\OODBBean
public
# __construct( RedBeanPHP\QueryWriter $writer, array|boolean $frozen = FALSE )

Constructor, requires a query writer.

Constructor, requires a query writer.

Parameters

$writer
writer
$frozen
mode of operation: TRUE (frozen), FALSE (default, fluid) or ARRAY (chilled)
public
# freeze( boolean|array $toggle )

Toggles fluid or frozen mode. In fluid mode the database structure is adjusted to accomodate your objects. In frozen mode this is not the case.

Toggles fluid or frozen mode. In fluid mode the database structure is adjusted to accomodate your objects. In frozen mode this is not the case.

You can also pass an array containing a selection of frozen types. Let's call this chilly mode, it's just like fluid mode except that certain types (i.e. tables) aren't touched.

Parameters

$toggle
TRUE if you want to use OODB instance in frozen mode
public boolean
# isFrozen( )

Returns the current mode of operation of RedBean. In fluid mode the database structure is adjusted to accomodate your objects. In frozen mode this is not the case.

Returns the current mode of operation of RedBean. In fluid mode the database structure is adjusted to accomodate your objects. In frozen mode this is not the case.

Returns

boolean
public boolean
# isChilled( string $type )

Determines whether a type is in the chill list. If a type is 'chilled' it's frozen, so its schema cannot be changed anymore. However other bean types may still be modified. This method is a convenience method for other objects to check if the schema of a certain type is locked for modification.

Determines whether a type is in the chill list. If a type is 'chilled' it's frozen, so its schema cannot be changed anymore. However other bean types may still be modified. This method is a convenience method for other objects to check if the schema of a certain type is locked for modification.

Parameters

$type
the type you wish to check

Returns

boolean
public RedBeanPHP\OODBBean
# dispense( string $type, string $number = 1, boolean $alwaysReturnArray = FALSE )

Dispenses a new bean (a OODBBean Bean Object) of the specified type. Always use this function to get an empty bean object. Never instantiate a OODBBean yourself because it needs to be configured before you can use it with RedBean. This function applies the appropriate initialization / configuration for you.

Dispenses a new bean (a OODBBean Bean Object) of the specified type. Always use this function to get an empty bean object. Never instantiate a OODBBean yourself because it needs to be configured before you can use it with RedBean. This function applies the appropriate initialization / configuration for you.

Parameters

$type
type of bean you want to dispense
$number
number of beans you would like to get
$alwaysReturnArray
if TRUE always returns the result as an array

Returns

RedBeanPHP\OODBBean
public
# setBeanHelper( RedBeanPHP\BeanHelper $beanhelper )

Sets bean helper to be given to beans. Bean helpers assist beans in getting a reference to a toolbox.

Sets bean helper to be given to beans. Bean helpers assist beans in getting a reference to a toolbox.

Parameters

$beanhelper
helper
public RedBeanPHP\BeanHelper
# getBeanHelper( )

Returns the current bean helper. Bean helpers assist beans in getting a reference to a toolbox.

Returns the current bean helper. Bean helpers assist beans in getting a reference to a toolbox.

Returns

RedBeanPHP\BeanHelper
public
# check( RedBeanPHP\OODBBean $bean )

Checks whether a OODBBean bean is valid. If the type is not valid or the ID is not valid it will throw an exception: Security.

Checks whether a OODBBean bean is valid. If the type is not valid or the ID is not valid it will throw an exception: Security.

Parameters

$bean
the bean that needs to be checked
public array
# find( string $type, array $conditions = array(), string $sql = NULL, array $bindings = array() )

Searches the database for a bean that matches conditions $conditions and sql $addSQL and returns an array containing all the beans that have been found.

Searches the database for a bean that matches conditions $conditions and sql $addSQL and returns an array containing all the beans that have been found.

Conditions need to take form:

array(
   'PROPERTY' => array( POSSIBLE VALUES... 'John', 'Steve' )
   'PROPERTY' => array( POSSIBLE VALUES... )
);

All conditions are glued together using the AND-operator, while all value lists are glued using IN-operators thus acting as OR-conditions.

Note that you can use property names; the columns will be extracted using the appropriate bean formatter.

Parameters

$type
type of beans you are looking for
$conditions
list of conditions
$sql
$addSQL SQL to be used in query
$bindings
a list of values to bind to query parameters

Returns

array
public array
# findCollection( string $type, string $sql = NULL, array $bindings = array() )

Same as find() but returns a BeanCollection.

Same as find() but returns a BeanCollection.

Parameters

$type
type of beans you are looking for
$sql
$addSQL SQL to be used in query
$bindings
a list of values to bind to query parameters

Returns

array
public boolean
# tableExists( string $table )

Checks whether the specified table already exists in the database. Not part of the Object Database interface!

Checks whether the specified table already exists in the database. Not part of the Object Database interface!

Deprecated

Use AQueryWriter::typeExists() instead.

Parameters

$table
table name

Returns

boolean
public integer|string
# store( RedBeanPHP\OODBBean|RedBeanPHP\SimpleModel $bean )

Stores a bean in the database. This method takes a OODBBean Bean Object $bean and stores it in the database. If the database schema is not compatible with this bean and RedBean runs in fluid mode the schema will be altered to store the bean correctly. If the database schema is not compatible with this bean and RedBean runs in frozen mode it will throw an exception. This function returns the primary key ID of the inserted bean.

Stores a bean in the database. This method takes a OODBBean Bean Object $bean and stores it in the database. If the database schema is not compatible with this bean and RedBean runs in fluid mode the schema will be altered to store the bean correctly. If the database schema is not compatible with this bean and RedBean runs in frozen mode it will throw an exception. This function returns the primary key ID of the inserted bean.

The return value is an integer if possible. If it is not possible to represent the value as an integer a string will be returned. We use explicit casts instead of functions to preserve performance (0.13 vs 0.28 for 10000 iterations on Core i3).

Parameters

$bean
bean to store

Returns

integer|string
public RedBeanPHP\OODBBean
# load( string $type, integer $id )

Loads a bean from the object database. It searches for a OODBBean Bean Object in the database. It does not matter how this bean has been stored. RedBean uses the primary key ID $id and the string $type to find the bean. The $type specifies what kind of bean you are looking for; this is the same type as used with the dispense() function. If RedBean finds the bean it will return the OODB Bean object; if it cannot find the bean RedBean will return a new bean of type $type and with primary key ID 0. In the latter case it acts basically the same as dispense().

Loads a bean from the object database. It searches for a OODBBean Bean Object in the database. It does not matter how this bean has been stored. RedBean uses the primary key ID $id and the string $type to find the bean. The $type specifies what kind of bean you are looking for; this is the same type as used with the dispense() function. If RedBean finds the bean it will return the OODB Bean object; if it cannot find the bean RedBean will return a new bean of type $type and with primary key ID 0. In the latter case it acts basically the same as dispense().

Important note: If the bean cannot be found in the database a new bean of the specified type will be generated and returned.

Parameters

$type
type of bean you want to load
$id
ID of the bean you want to load

Returns

RedBeanPHP\OODBBean
public
# trash( RedBeanPHP\OODBBean|RedBeanPHP\SimpleModel $bean )

Removes a bean from the database. This function will remove the specified OODBBean Bean Object from the database.

Removes a bean from the database. This function will remove the specified OODBBean Bean Object from the database.

Parameters

$bean
bean you want to remove from database
public array
# batch( string $type, array $ids )

Returns an array of beans. Pass a type and a series of ids and this method will bring you the corresponding beans.

Returns an array of beans. Pass a type and a series of ids and this method will bring you the corresponding beans.

important note: Because this method loads beans using the load() function (but faster) it will return empty beans with ID 0 for every bean that could not be located. The resulting beans will have the passed IDs as their keys.

Parameters

$type
type of beans
$ids
ids to load

Returns

array
public array
# convertToBeans( string $type, array $rows, string $mask = NULL )

This is a convenience method; it converts database rows (arrays) into beans. Given a type and a set of rows this method will return an array of beans of the specified type loaded with the data fields provided by the result set from the database.

This is a convenience method; it converts database rows (arrays) into beans. Given a type and a set of rows this method will return an array of beans of the specified type loaded with the data fields provided by the result set from the database.

Parameters

$type
type of beans you would like to have
$rows
rows from the database result
$mask
mask to apply for meta data

Returns

array
public integer
# count( string $type, string $addSQL = '', array $bindings = array() )

Counts the number of beans of type $type. This method accepts a second argument to modify the count-query. A third argument can be used to provide bindings for the SQL snippet.

Counts the number of beans of type $type. This method accepts a second argument to modify the count-query. A third argument can be used to provide bindings for the SQL snippet.

Parameters

$type
type of bean we are looking for
$addSQL
additional SQL snippet
$bindings
parameters to bind to SQL

Returns

integer
public boolean
# wipe( string $type )

Trash all beans of a given type. Wipes an entire type of bean.

Trash all beans of a given type. Wipes an entire type of bean.

Parameters

$type
type of bean you wish to delete all instances of

Returns

boolean
public RedBeanPHP\AssociationManager
# getAssociationManager( )

Returns an Association Manager for use with OODB. A simple getter function to obtain a reference to the association manager used for storage and more.

Returns an Association Manager for use with OODB. A simple getter function to obtain a reference to the association manager used for storage and more.

Returns

RedBeanPHP\AssociationManager
public
# setAssociationManager( RedBeanPHP\AssociationManager $assocManager )

Sets the association manager instance to be used by this OODB. A simple setter function to set the association manager to be used for storage and more.

Sets the association manager instance to be used by this OODB. A simple setter function to set the association manager to be used for storage and more.

Parameters

$assocManager
$assoc sets the association manager to be used
public RedBeanPHP\Repository
# getCurrentRepository( )

Returns the currently used repository instance. For testing purposes only.

Returns the currently used repository instance. For testing purposes only.

Returns

RedBeanPHP\Repository
public
# bindFunc( string $mode, string $field, string $function )

Binds an SQL function to a column. This method can be used to setup a decode/encode scheme or perform UUID insertion. This method is especially useful for handling MySQL spatial columns, because they need to be processed first using the asText/GeomFromText functions.

Binds an SQL function to a column. This method can be used to setup a decode/encode scheme or perform UUID insertion. This method is especially useful for handling MySQL spatial columns, because they need to be processed first using the asText/GeomFromText functions.

Parameters

$mode
mode to set function for, i.e. read or write
$field
field (table.column) to bind SQL function to
$function
SQL function to bind to field
Methods inherited from RedBeanPHP\Observable
addEventListener(), signal()
Properties summary
protected array $chillList
# array()
protected array $stash
# NULL
protected integer $nesting
# 0
protected RedBeanPHP\Adapter\DBAdapter $writer
#
protected boolean $isFrozen
# FALSE
protected FacadeBeanHelper $beanhelper
# NULL
protected RedBeanPHP\AssociationManager $assocManager
# NULL
protected RedBeanPHP\Repository $repository
# NULL
protected RedBeanPHP\Repository\Frozen $frozenRepository
# NULL
protected RedBeanPHP\Repository\Fluid $fluidRepository
# NULL
protected static boolean $autoClearHistoryAfterStore
# FALSE
API documentation generated by ApiGen