PhpToolCase
Api Documentation Version 0.9.2
|
Public Member Functions | |
__construct (PDO $pdo=null) | |
Adds the pdo instance to the query builder object. More... | |
table ($table) | |
Adds tables to the query. More... | |
select ($columns) | |
Sets the columns to be selected. More... | |
rawSelect ($rawClause) | |
Adds A raw where clause to the query. More... | |
sanitize ($value) | |
Sanitize unsafe data. More... | |
raw ($value) | |
Adds a raw value to a where clause in the query. More... | |
addBackTicks ($string) | |
Adds backticks to the passed string. More... | |
join ($table, $first, $operator=null, $second=null, $type= 'inner') | |
Creates a join based on the parameters. More... | |
on ($column, $operator, $value, $type= 'and') | |
Joins columns based on values. More... | |
where ($column, $operator=null, $value=null, $type= 'and') | |
Adds where clouses to the query. More... | |
find ($id) | |
returns 1 record from a given table based on the id. More... | |
run ($query=null, $bind=null, $type=null) | |
Runs queries if pdo object is present. More... | |
row ($column=null) | |
Retrieves 1 row from a given table. More... | |
prepare () | |
Builds the query and returns it as string with place holders. More... | |
order ($column, $direction= 'asc') | |
Adds order to the query. More... | |
group ($column) | |
Adds group by to the query. More... | |
limit ($start, $results=null) | |
Adds limit to the query. More... | |
countRows () | |
Returns number of affected rows from last query. More... | |
lastId () | |
Retrieves last inserted id. More... | |
insert ($array) | |
Inserts a record in a given table. More... | |
update ($array, $id=null) | |
Updates records in a given table based on a where clause. More... | |
delete ($id=null) | |
Deletes rows from a given table based on a where clause. More... | |
reset () | |
Resets the query parameters. More... | |
setFetchMode ($mode, $class=null) | |
Sets fetch mode for the next query. More... | |
__call ($method, $args) | |
Adds where operators and joins to the query. More... | |
Protected Member Functions | |
_buildQuery () | |
Builds the query based on the type. More... | |
_executeSql ($mode=1) | |
Executes sql queries. More... | |
_bind ($pos, $value, $type=null) | |
Binds values to the query. More... | |
_addAndOR ($value) | |
adds "and" or "or" to the query More... | |
_buildWhereClause ($type, $column, $operator=null, $value=null) | |
Builds the where clause. More... | |
_buildInClause ($column, $array, $type= 'in') | |
Creates a "where in" statement. More... | |
_buildBetweenClause ($column, $start, $end, $type= 'between') | |
Creates a "where between" statement. More... | |
_checkRawValue ($value) | |
Checks if a rwa value was added. More... | |
_checkOperator ($operator) | |
_runClosure (Closure $function, $type) | |
Runs closures for "where" and "joins". More... | |
_checkPdo () | |
Checks if Pdo object was passed to the constructor to run queries. More... | |
_isTableSet () | |
Checks if a table was set. More... | |
_generateRandomId () | |
Generates a random numeric string to secure the raw function. More... | |
_fireEvent ($data) | |
Fires "ptc.query" event if PtcEvent class is present. More... | |
_getEventClass () | |
Retrieves the event class names and it's namespace. More... | |
_debugQuery ($string, $data) | |
Sends queries to the Debugger & Logger if present. More... | |
Static Protected Member Functions | |
static | _debug ($string, $statement=null, $category= 'QueryBuilder') |
Send messsages to the PtcDebug class if present. More... | |
static | _debugBuffer ($reference, $type=null, $string=null, $statement=null) |
Adds execution time and query results to the PtcDebug class. More... | |
Protected Attributes | |
$_bindLimit = array( ) | |
Limit property for the query. More... | |
$_columns = '*' | |
Columns property for the query. More... | |
$_table = null | |
Table property for the query. More... | |
$_where = null | |
Where property for the query. More... | |
$_orderBy = null | |
Order by property for the query. More... | |
$_groupBy = null | |
Group by property for the query. More... | |
$_limit = null | |
Limit property for the query. More... | |
$_pdo = null | |
Pdo object prperty to run queries. More... | |
$_query = null | |
Prepared query property. More... | |
$_lastQuery = null | |
Last query property. More... | |
$_currentQuery = null | |
Current query property. More... | |
$_currentQueryType = null | |
Current query type property. More... | |
$_values = null | |
Bind values property. More... | |
$_bindings = array( ) | |
Place holders property. More... | |
$_operators | |
Operator for where and join clauses property. More... | |
$_returnStatements = array( 'SHOW' , 'SELECT' ) | |
Queries that need a return result propeerty. More... | |
$_join = null | |
Join Property. More... | |
$_randomId = null | |
Random Id property for raw values. More... | |
$_isClosure = false | |
Property that checks if class is running a closure. More... | |
$_fetchMode = array( ) | |
Fecth mode pdo property for current query. More... | |
$_eventClass = '\PtcEvent' | |
Event class name property. More... | |
__construct | ( | PDO | $pdo = null | ) |
Adds the pdo instance to the query builder object.
See Getting Started
object | $pdo | the pdo object |
Definition at line 19 of file PtcQueryBuilder.php.
__call | ( | $method, | |
$args | |||
) |
Adds where operators and joins to the query.
string | $method | the method to call |
array | $args | arguments used by the called methods |
Definition at line 421 of file PtcQueryBuilder.php.
|
protected |
adds "and" or "or" to the query
string | $value | the value to check |
Definition at line 653 of file PtcQueryBuilder.php.
|
protected |
Binds values to the query.
mixed | $pos | the param position if numeric |
mixed | $value | the value to bind the place holder to |
contants | $type | a pdo constant to bind values |
Definition at line 631 of file PtcQueryBuilder.php.
|
protected |
Creates a "where between" statement.
Definition at line 719 of file PtcQueryBuilder.php.
|
protected |
Creates a "where in" statement.
Definition at line 696 of file PtcQueryBuilder.php.
|
protected |
Builds the query based on the type.
Definition at line 548 of file PtcQueryBuilder.php.
|
protected |
Builds the where clause.
string | $type | specifies "and"/"or" |
string | $column | the table column |
string | $operator | the operator to use |
mixed | $value | the value to check |
Definition at line 674 of file PtcQueryBuilder.php.
|
protected |
Definition at line 755 of file PtcQueryBuilder.php.
|
protected |
Checks if Pdo object was passed to the constructor to run queries.
Definition at line 780 of file PtcQueryBuilder.php.
|
protected |
Checks if a rwa value was added.
Definition at line 744 of file PtcQueryBuilder.php.
|
staticprotected |
Send messsages to the PtcDebug class if present.
mixed | $string | the string to pass |
mixed | $statement | some statement if required |
string | $category | a category for the messages panel |
Definition at line 832 of file PtcQueryBuilder.php.
|
staticprotected |
Adds execution time and query results to the PtcDebug class.
string | $reference | a reference to look for ("$statement") |
string | $type | the type of debug (timer, attach) |
mixed | $string | the string to pass |
mixed | $statement | some new statement if required |
Definition at line 859 of file PtcQueryBuilder.php.
|
protected |
Sends queries to the Debugger & Logger if present.
Definition at line 841 of file PtcQueryBuilder.php.
|
protected |
Executes sql queries.
See Specifying The Return Type
numeric | $mode | the type of query (1,2,3) |
Definition at line 587 of file PtcQueryBuilder.php.
|
protected |
Fires "ptc.query" event if PtcEvent class is present.
See Observer Events
Definition at line 812 of file PtcQueryBuilder.php.
|
protected |
Generates a random numeric string to secure the raw function.
Definition at line 805 of file PtcQueryBuilder.php.
|
protected |
Retrieves the event class names and it's namespace.
Definition at line 822 of file PtcQueryBuilder.php.
|
protected |
Checks if a table was set.
Definition at line 793 of file PtcQueryBuilder.php.
|
protected |
Runs closures for "where" and "joins".
Definition at line 767 of file PtcQueryBuilder.php.
addBackTicks | ( | $string | ) |
Adds backticks to the passed string.
string | $string | the column or table name |
Definition at line 115 of file PtcQueryBuilder.php.
countRows | ( | ) |
Returns number of affected rows from last query.
See Counting Rows
Definition at line 311 of file PtcQueryBuilder.php.
delete | ( | $id = null | ) |
Deletes rows from a given table based on a where clause.
See Delete Records
numeric | $id | a row id |
Definition at line 365 of file PtcQueryBuilder.php.
find | ( | $id | ) |
returns 1 record from a given table based on the id.
See Retrieving 1 Record From A Table
numeric | $id | the record id |
Definition at line 182 of file PtcQueryBuilder.php.
group | ( | $column | ) |
Adds group by to the query.
string | $column | the column names |
Definition at line 283 of file PtcQueryBuilder.php.
insert | ( | $array | ) |
Inserts a record in a given table.
See Insert Recods
array | $array | an associative array , Ex.: array( column => value ) |
Definition at line 329 of file PtcQueryBuilder.php.
join | ( | $table, | |
$first, | |||
$operator = null , |
|||
$second = null , |
|||
$type = 'inner' |
|||
) |
Creates a join based on the parameters.
See Joins
string | $table | the name of the table to join |
string | $first | the first column |
string | $operator | the operator to use for the join |
string | $second | the second column |
string | $type | the type of join |
Definition at line 130 of file PtcQueryBuilder.php.
lastId | ( | ) |
Retrieves last inserted id.
See Last Inserted Id
Definition at line 324 of file PtcQueryBuilder.php.
limit | ( | $start, | |
$results = null |
|||
) |
Adds limit to the query.
string | int | $start | an integer value or a place holder |
string | int | $results | an integer value or a place holder |
Definition at line 294 of file PtcQueryBuilder.php.
on | ( | $column, | |
$operator, | |||
$value, | |||
$type = 'and' |
|||
) |
Joins columns based on values.
See Joins
string | $column | the first column for the join |
string | $operator | the operator to use |
string | $value | the second column for the join |
string | $type | adds "and" , "or" to multiple joins statements |
Definition at line 146 of file PtcQueryBuilder.php.
order | ( | $column, | |
$direction = 'asc' |
|||
) |
Adds order to the query.
string | $column | the column names |
string | $direction | asc or desc |
Definition at line 272 of file PtcQueryBuilder.php.
prepare | ( | ) |
Builds the query and returns it as string with place holders.
Definition at line 252 of file PtcQueryBuilder.php.
raw | ( | $value | ) |
Adds a raw value to a where clause in the query.
See Raw Values
string | $value | a raw value for the sql query |
Definition at line 109 of file PtcQueryBuilder.php.
rawSelect | ( | $rawClause | ) |
Adds A raw where clause to the query.
See Raw Statements
string | $rawClause | the where clause |
Definition at line 88 of file PtcQueryBuilder.php.
reset | ( | ) |
Resets the query parameters.
Definition at line 387 of file PtcQueryBuilder.php.
row | ( | $column = null | ) |
Retrieves 1 row from a given table.
See Retrieving 1 Record From A Table
string | $column | column name to return only 1 value as string |
Definition at line 228 of file PtcQueryBuilder.php.
run | ( | $query = null , |
|
$bind = null , |
|||
$type = null |
|||
) |
Runs queries if pdo object is present.
See Getting Started
string | $query | the query to run |
array | $bind | the values to bind to the query |
numeric | $type | the query type ( 1,2,3) |
Definition at line 199 of file PtcQueryBuilder.php.
sanitize | ( | $value | ) |
Sanitize unsafe data.
string | $value | the value to sanitize |
Definition at line 98 of file PtcQueryBuilder.php.
select | ( | $columns | ) |
Sets the columns to be selected.
See Specifying Columns To Be Selected
array | string | $columns | the columns to be selected |
Definition at line 58 of file PtcQueryBuilder.php.
setFetchMode | ( | $mode, | |
$class = null |
|||
) |
Sets fetch mode for the next query.
constant | $mode | a pdo constant |
mixed | $class | a class name if needed |
Definition at line 406 of file PtcQueryBuilder.php.
table | ( | $table | ) |
Adds tables to the query.
array | string | $table | the name of the table |
Definition at line 29 of file PtcQueryBuilder.php.
update | ( | $array, | |
$id = null |
|||
) |
Updates records in a given table based on a where clause.
See Update Records
array | $array | associative array of values, Ex.: array( column => value ) |
numeric | $id | a row id |
Definition at line 342 of file PtcQueryBuilder.php.
where | ( | $column, | |
$operator = null , |
|||
$value = null , |
|||
$type = 'and' |
|||
) |
Adds where clouses to the query.
See Where Operators
mixed | $column | the column name or a closure function |
string | $operator | the operator to use for the where clause |
string | $value | the value to look for in the column |
string | $type | the type of where clasuse |
Definition at line 162 of file PtcQueryBuilder.php.
|
protected |
Place holders property.
Definition at line 515 of file PtcQueryBuilder.php.
|
protected |
Limit property for the query.
Definition at line 463 of file PtcQueryBuilder.php.
|
protected |
Columns property for the query.
Definition at line 467 of file PtcQueryBuilder.php.
|
protected |
Current query property.
Definition at line 503 of file PtcQueryBuilder.php.
|
protected |
Current query type property.
Definition at line 507 of file PtcQueryBuilder.php.
|
protected |
Event class name property.
Definition at line 544 of file PtcQueryBuilder.php.
|
protected |
Fecth mode pdo property for current query.
Definition at line 540 of file PtcQueryBuilder.php.
|
protected |
Group by property for the query.
Definition at line 483 of file PtcQueryBuilder.php.
|
protected |
Property that checks if class is running a closure.
Definition at line 536 of file PtcQueryBuilder.php.
|
protected |
Join Property.
Definition at line 528 of file PtcQueryBuilder.php.
|
protected |
Last query property.
Definition at line 499 of file PtcQueryBuilder.php.
|
protected |
Limit property for the query.
Definition at line 487 of file PtcQueryBuilder.php.
|
protected |
Operator for where and join clauses property.
Definition at line 519 of file PtcQueryBuilder.php.
|
protected |
Order by property for the query.
Definition at line 479 of file PtcQueryBuilder.php.
|
protected |
Pdo object prperty to run queries.
Definition at line 491 of file PtcQueryBuilder.php.
|
protected |
Prepared query property.
Definition at line 495 of file PtcQueryBuilder.php.
|
protected |
Random Id property for raw values.
Definition at line 532 of file PtcQueryBuilder.php.
|
protected |
Queries that need a return result propeerty.
Definition at line 524 of file PtcQueryBuilder.php.
|
protected |
Table property for the query.
Definition at line 471 of file PtcQueryBuilder.php.
|
protected |
Bind values property.
Definition at line 511 of file PtcQueryBuilder.php.
|
protected |
Where property for the query.
Definition at line 475 of file PtcQueryBuilder.php.