$max
$max : integer
PDO Driver This Driver implements the RedBean Driver API.
for RedBeanPHP. This is the standard / default database driver for RedBeanPHP.
$logger : \RedBeanPHP\Logger|NULL
__construct(string|\PDO $dsn, string $user = NULL, string $pass = NULL, $options = array()) : void
Constructor. You may either specify dsn, user and password or just give an existing PDO connection.
Usage:
$driver = new RPDO( $dsn, $user, $password );
The example above illustrates how to create a driver instance from a database connection string (dsn), a username and a password. It's also possible to pass a PDO object.
Usage:
$driver = new RPDO( $existingConnection );
The second example shows how to create an RPDO instance from an existing PDO object.
string|\PDO | $dsn | database connection string |
string | $user | optional, username to sign in |
string | $pass | optional, password for connection login |
$options |
stringifyFetches(boolean $bool)
Sets PDO in stringify fetch mode.
If set to TRUE, this method will make sure all data retrieved from the database will be fetched as a string. Default: TRUE.
To set it to FALSE...
Usage:
R::getDatabaseAdapter()->getDatabase()->stringifyFetches( FALSE );
Important! Note, this method only works if you set the value BEFORE the connection has been establish. Also, this setting ONLY works with SOME drivers. It's up to the driver to honour this setting.
boolean | $bool |
getMysqlEncoding(boolean $retCol = FALSE) : string|array
Returns the best possible encoding for MySQL based on version data.
This method can be used to obtain the best character set parameters possible for your database when constructing a table creation query containing clauses like: CHARSET=... COLLATE=... This is a MySQL-specific method and not part of the driver interface.
Usage:
$charset_collate = $this->adapter->getDatabase()->getMysqlEncoding( TRUE );
boolean | $retCol | pass TRUE to return both charset/collate |
setMaxIntBind(integer $max) : integer
Sets the maximum value to be bound as integer, normally this value equals PHP's MAX INT constant, however sometimes PDO driver bindings cannot bind large integers as integers.
This method allows you to manually set the max integer binding value to manage portability/compatibility issues among different PHP builds. This method will return the old value.
integer | $max | maximum value for integer bindings |
setPDO(\PDO $pdo, array $options = array()) : void
Directly sets PDO instance into driver.
This method might improve performance, however since the driver does not configure this instance terrible things may happen... only use this method if you are an expert on RedBeanPHP, PDO and UTF8 connections and you know your database server VERY WELL.
*attributes:
\PDO | $pdo | PDO instance |
array | $options | Options to apply |
Execute(string $sql, array $bindings = array()) : integer
Executes SQL code and allows key-value binding.
This function allows you to provide an array with values to bind to query parameters. For instance you can bind values to question marks in the query. Each value in the array corresponds to the question mark in the query that matches the position of the value in the array. You can also bind values using explicit keys, for instance array(":key"=>123) will bind the integer 123 to the key :key in the SQL. This method has no return value.
string | $sql | SQL query to execute |
array | $bindings | list of values to bind to SQL snippet |
Affected Rows
GetCursor(string $sql, array $bindings = array()) : \RedBeanPHP\Cursor
Returns a cursor-like object from the database.
string | $sql | SQL query to execute |
array | $bindings | list of values to bind to SQL snippet |
setDebugMode( $tf, $logger = NULL) : void
Toggles debug mode. In debug mode the driver will print all SQL to the screen together with some information about the results.
This method is for more fine-grained control. Normally you should use the facade to start the query debugger for you. The facade will manage the object wirings necessary to use the debugging functionality.
Usage (through facade):
R::debug( TRUE );
...rest of program...
R::debug( FALSE );
The example above illustrates how to use the RedBeanPHP query debugger through the facade.
$tf | ||
$logger |
setLogger(\RedBeanPHP\Logger $logger) : self
Injects Logger object.
Sets the logger instance you wish to use.
This method is for more fine-grained control. Normally you should use the facade to start the query debugger for you. The facade will manage the object wirings necessary to use the debugging functionality.
Usage (through facade):
R::debug( TRUE );
...rest of program...
R::debug( FALSE );
The example above illustrates how to use the RedBeanPHP query debugger through the facade.
\RedBeanPHP\Logger | $logger | the logger instance to be used for logging |
getLogger() : \RedBeanPHP\Logger
Gets Logger object.
Returns the currently active Logger instance.
getDatabaseType() : string
Returns the name of database driver for PDO.
Uses the PDO attribute DRIVER NAME to obtain the name of the PDO driver. Use this method to identify the current PDO driver used to provide access to the database. Example of a database driver string:
mysql
Usage:
echo R::getDatabaseAdapter()->getDatabase()->getDatabaseType();
The example above prints the current database driver string to stdout.
Note that this is a driver-specific method, not part of the driver interface. This method might not be available in other drivers since it relies on PDO.
getDatabaseVersion() : mixed
Returns the version identifier string of the database client.
This method can be used to identify the currently installed database client. Note that this method will also establish a connection (because this is required to obtain the version information).
Example of a version string:
mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $
Usage:
echo R::getDatabaseAdapter()->getDatabase()->getDatabaseVersion();
The example above will print the version string to stdout.
Note that this is a driver-specific method, not part of the driver interface. This method might not be available in other drivers since it relies on PDO.
To obtain the database server version, use getDatabaseServerVersion() instead.
getPDO() : \PDO
Returns the underlying PHP PDO instance.
For some low-level database operations you'll need access to the PDO object. Not that this method is only available in RPDO and other PDO based database drivers for RedBeanPHP. Other drivers may not have a method like this. The following example demonstrates how to obtain a reference to the PDO instance from the facade:
Usage:
$pdo = R::getDatabaseAdapter()->getDatabase()->getPDO();
close() : void
Closes the database connection.
While database connections are closed automatically at the end of the PHP script, closing database connections is generally recommended to improve performance. Closing a database connection will immediately return the resources to PHP.
Usage:
R::setup( ... );
... do stuff ...
R::close();
resetCounter() : self
Resets the query counter.
The query counter can be used to monitor the number of database queries that have been processed according to the database driver. You can use this to monitor the number of queries required to render a page.
Usage:
R::resetQueryCount();
echo R::getQueryCount() . ' queries processed.';
getQueryCount() : integer
Returns the number of SQL queries processed.
This method returns the number of database queries that have been processed according to the database driver. You can use this to monitor the number of queries required to render a page.
Usage:
echo R::getQueryCount() . ' queries processed.';
setInitQuery(string $sql) : self
Sets a query to be executed upon connecting to the database.
This method provides an opportunity to configure the connection to a database through an SQL-based interface. Objects can provide an SQL string to be executed upon establishing a connection to the database. This has been used to solve issues with default foreign key settings in SQLite3 for instance, see Github issues:
string | $sql | SQL query to run upon connecting to database |
bindParams(\PDOStatement $statement, array $bindings) : void
Binds parameters. This method binds parameters to a PDOStatement for Query Execution. This method binds parameters as NULL, INTEGER or STRING and supports both named keys and question mark keys.
\PDOStatement | $statement | PDO Statement instance |
array | $bindings | values that need to get bound to the statement |
runQuery(string $sql, array $bindings, array $options = array()) : mixed
This method runs the actual SQL query and binds a list of parameters to the query.
slots. The result of the query will be stored in the protected property $rs (always array). The number of rows affected (result of rowcount, if supported by database) is stored in protected property $affectedRows. If the debug flag is set this function will send debugging output to screen buffer.
string | $sql | the SQL string to be send to database server |
array | $bindings | the values that need to get bound to the query slots |
array | $options |
hasCap(string $db_cap) : integer|false
Determine if a database supports a particular feature.
Currently this function can be used to detect the following features:
Usage:
$this->hasCap( 'utf8mb4_520' );
By default, RedBeanPHP uses this method under the hood to make sure you use the latest UTF8 encoding possible for your database.
string | $db_cap | identifier of database capability |
Whether the database feature is supported, FALSE otherwise.