BELONGS_TO
BELONGS_TO
Simple implement of active record in PHP.<br /> Using magic function to implement more smarty functions.<br /> Can using chain method calls, to build concise and compactness program.<br />
reset() : \ActiveRecord
function to reset the $params and $sqlExpressions.
return $this, can using chain method calls.
dirty(array $dirty = array()) : \ActiveRecord
function to SET or RESET the dirty data.
array | $dirty | The dirty data will be set, or empty array to reset the dirty data. |
return $this, can using chain method calls.
find(integer $id = null) : boolean|\ActiveRecord
function to find one record and assign in to current object.
integer | $id | If call this function using this param, will find record by using this id. If not set, just find the first record in database. |
if find record, assign in to current object and return it, other wise return "false".
update() : boolean|\ActiveRecord
function to build update SQL, and update current record in database, just write the dirty data into database.
if update success return current object, other wise return false.
insert() : boolean|\ActiveRecord
function to build insert SQL, and insert current record into database.
if insert success return current object, other wise return false.
_query(string $sql, array $param = array(), \ActiveRecord $obj = null, boolean $single = false) : boolean|\ActiveRecord|array
helper function to query one record by sql and params.
string | $sql | The SQL to find record. |
array | $param | The param will be bind to PDOStatement. |
\ActiveRecord | $obj | The object, if find record in database, will assign the attributes in to this object. |
boolean | $single | if set to true, will find record and fetch in current object, otherwise will find all records. |
__call(string $name, array $args) : mixed
magic function to make calls witch in function mapping stored in $operators and $sqlPart.
also can call function of PDO object.
string | $name | function name |
array | $args | The arguments of the function. |
Return the result of callback or the current object to make chain method calls.
wrap(string $op = null) : \ActiveRecord
make wrap when build the SQL expressions of WHWRE.
string | $op | If give this param will build one WrapExpressions include the stored expressions add into WHWRE. otherwise wil stored the expressions into array. |
return $this, can using chain method calls.
addCondition(string $field, string $operator, mixed $value, string $op = 'AND', string $name = 'where')
helper function to add condition into WHERE.
create the SQL Expressions.
string | $field | The field name, the source of Expressions |
string | $operator | |
mixed | $value | the target of the Expressions |
string | $op | the operator to concat this Expressions into WHERE or SET statment. |
string | $name | The Expression will contact to. |
_addExpression(\Expressions $exp, string $operator)
helper function to make wrapper. Stored the expression in to array.
\Expressions | $exp | The expression will be stored. |
string | $operator | The operator to concat this Expressions into WHERE statment. |
_addCondition(\Expressions $exp, string $operator, string $name = 'where')
helper function to add condition into WHERE.
\Expressions | $exp | The expression will be concat into WHERE or SET statment. |
string | $operator | the operator to concat this Expressions into WHERE or SET statment. |
string | $name | The Expression will contact to. |
_buildSqlCallback(string $n, integer $i, \ActiveRecord $o) : string
helper function to build SQL with sql parts.
string | $n | The SQL part will be build. |
integer | $i | The index of $n in $sqls array. |
\ActiveRecord | $o | The refrence to $this |