Propel API
Class

BasePeer

class BasePeer

This is a utility class for all generated Peer classes in the system.

Peer classes are responsible for isolating all of the database access
for a specific business object. They execute all of the SQL
against the database. Over time this class has grown to include
utility methods which ease execution of cross-database queries and
the implementation of concrete Peers.

Constants

TYPE_PHPNAME

phpname type e.g.

'AuthorId'

TYPE_STUDLYPHPNAME

studlyphpname type e.g.

'authorId'

TYPE_COLNAME

column (peer) name type e.g.

'book.AUTHOR_ID'

TYPE_RAW_COLNAME

column part of the column peer name e.g.

'AUTHOR_ID'

TYPE_FIELDNAME

column fieldname type e.g.

'author_id'

TYPE_NUM

num type simply the numerical array index, e.g.

4

Methods

static  getFieldnames($classname, $type = self::TYPE_PHPNAME)

static  translateFieldname($classname, $fieldname, $fromType, $toType)

static int doDelete(Criteria $criteria, PropelPDO $con)

Method to perform deletes based on values and keys in a Criteria.

static int doDeleteAll(string $tableName, PropelPDO $con, string $databaseName = null)

Method to deletes all contents of specified table.

static mixed doInsert(Criteria $criteria, PropelPDO $con)

Method to perform inserts based on values and keys in a Criteria.

static int doUpdate(Criteria $selectCriteria, Criteria $updateValues, PropelPDO $con)

Method used to update rows in the DB.

static PDOStatement doSelect(Criteria $criteria, PropelPDO $con = null)

Executes query build by createSelectSql() and returns the resultset statement.

static PDOStatement doCount(Criteria $criteria, PropelPDO $con = null)

Executes a COUNT query using either a simple SQL rewrite or, for more complex queries, a sub-select of the SQL created by createSelectSql() and returns the statement.

static  doValidate(string $dbName, string $tableName, array $columns)

Applies any validators that were defined in the schema to the specified columns.

static  needsSelectAliases(Criteria $criteria)

Checks whether the Criteria needs to use column aliasing This is implemented in a service class rather than in Criteria itself in order to avoid doing the tests when it's not necessary (e.g.

static string createSelectSql(Criteria $criteria, array $params)

Method to create an SQL query based on values in a Criteria.

static Validator getValidator(string $classname)

This function searches for the given validator $name under propel/validator/$name.php, imports and caches it.

Details

at line 75
static public getFieldnames($classname, $type = self::TYPE_PHPNAME)

Parameters

$classname
$type

at line 85
static public translateFieldname($classname, $fieldname, $fromType, $toType)

Parameters

$classname
$fieldname
$fromType
$toType

at line 109
static public int doDelete(Criteria $criteria, PropelPDO $con)

Method to perform deletes based on values and keys in a Criteria.

Parameters

Criteria $criteria The criteria to use.
PropelPDO $con A PropelPDO connection object.

Return Value

int The number of rows affected by last statement execution. For most uses there is only one delete statement executed, so this number will correspond to the number of rows affected by the call to this method. Note that the return value does require that this information is returned (supported) by the PDO driver.

Exceptions

PropelException

at line 177
static public int doDeleteAll(string $tableName, PropelPDO $con, string $databaseName = null)

Method to deletes all contents of specified table.

This method is invoked from generated Peer classes like this:
<code>
public static function doDeleteAll($con = null)
{
if ($con === null) $con = Propel::getConnection(self::DATABASE_NAME);
BasePeer::doDeleteAll(self::TABLE_NAME, $con, self::DATABASE_NAME);
}
</code>

Parameters

string $tableName The name of the table to empty.
PropelPDO $con A PropelPDO connection object.
string $databaseName the name of the database.

Return Value

int The number of rows affected by the statement. Note that the return value does require that this information is returned (supported) by the Propel db driver.

Exceptions

PropelException - wrapping SQLException caught from statement execution.

at line 217
static public mixed doInsert(Criteria $criteria, PropelPDO $con)

Method to perform inserts based on values and keys in a Criteria.

<p>
If the primary key is auto incremented the data in Criteria
will be inserted and the auto increment value will be returned.
<p>
If the primary key is included in Criteria then that value will
be used to insert the row.
<p>
If no primary key is included in Criteria then we will try to
figure out the primary key from the database map and insert the
row with the next available id using util.db.IDBroker.
<p>
If no primary key is defined for the table the values will be
inserted as specified in Criteria and null will be returned.

Parameters

Criteria $criteria Object containing values to insert.
PropelPDO $con A PropelPDO connection.

Return Value

mixed The primary key for the new row if (and only if!) the primary key is auto-generated. Otherwise will return <code>null</code>.

Exceptions

PropelException

at line 329
static public int doUpdate(Criteria $selectCriteria, Criteria $updateValues, PropelPDO $con)

Method used to update rows in the DB.

Rows are selected based
on selectCriteria and updated using values in updateValues.
<p>
Use this method for performing an update of the kind:
<p>
WHERE some_column = some value AND could_have_another_column =
another value AND so on.

Parameters

Criteria $selectCriteria A Criteria object containing values used in where clause.
Criteria $updateValues A Criteria object containing values used in set clause.
PropelPDO $con The PropelPDO connection object to use.

Return Value

int The number of rows affected by last update statement. For most uses there is only one update statement executed, so this number will correspond to the number of rows affected by the call to this method. Note that the return value does require that this information is returned (supported) by the Propel db driver.

Exceptions

PropelException

at line 461
static public PDOStatement doSelect(Criteria $criteria, PropelPDO $con = null)

Executes query build by createSelectSql() and returns the resultset statement.

Parameters

Criteria $criteria A Criteria.
PropelPDO $con A PropelPDO connection to use.

Return Value

PDOStatement The resultset.

Exceptions

PropelException

See also

createSelectSql()

at line 503
static public PDOStatement doCount(Criteria $criteria, PropelPDO $con = null)

Executes a COUNT query using either a simple SQL rewrite or, for more complex queries, a sub-select of the SQL created by createSelectSql() and returns the statement.

Parameters

Criteria $criteria A Criteria.
PropelPDO $con A PropelPDO connection to use.

Return Value

PDOStatement The resultset statement.

Exceptions

PropelException

See also

createSelectSql()

at line 561
static public doValidate(string $dbName, string $tableName, array $columns)

Applies any validators that were defined in the schema to the specified columns.

Parameters

string $dbName The name of the database
string $tableName The name of the table
array $columns Array of column names as key and column values as value.

at line 617
static public needsSelectAliases(Criteria $criteria)

Checks whether the Criteria needs to use column aliasing This is implemented in a service class rather than in Criteria itself in order to avoid doing the tests when it's not necessary (e.g.

for SELECTs)

Parameters

Criteria $criteria

at line 646
static public string createSelectSql(Criteria $criteria, array $params)

Method to create an SQL query based on values in a Criteria.

This method creates only prepared statement SQL (using ? where values
will go). The second parameter ($params) stores the values that need
to be set before the statement is executed. The reason we do it this way
is to let the PDO layer handle all escaping & value formatting.

Parameters

Criteria $criteria Criteria for the SELECT query.
array $params &$params Parameters that are to be replaced in prepared statement.

Return Value

string

Exceptions

PropelException Trouble creating the query string.

at line 869
static public Validator getValidator(string $classname)

This function searches for the given validator $name under propel/validator/$name.php, imports and caches it.

Parameters

string $classname The dot-path name of class (e.g. myapp.propel.MyValidator)

Return Value

Validator object or null if not able to instantiate validator class (and error will be logged in this case)