PHPDevShell 3.1.3-Stable
PHP OOP RAD Development Framework
PHPDS_query Class Reference
Inheritance diagram for PHPDS_query:
PHPDS_dependant

Public Member Functions

 construct ()
 connector ($connector=null)
 invoke ($parameters=null)
 query ($parameters=null)
 querySQL ($sql)
 queryDebug ($sql)
 rows ($parameters=null)
 sql ($sql=null)
 build ($parameters=null)
 extraBuild ($parameters=null)
 preBuild ()
 addWhere ($sql, $mode= 'AND')
 protectArray (array $a, $quote= '')
 protectString ($string)
 getKey ($row=null)
 asWhole ()
 typeCast ($values, $key=null)
 getResults ()
 asArray ($field)
 asLine ($row_number=null)
 asOne ($row_number=null, $field=null)
 count ()
 total ()
 limit ($limit)
 checkParameters (&$parameters=null)
 checkResults (&$results=null)
 debugInstance ($domain=null)
 extra_build ($parameters=null)
 protect_array (array $a)
 get_key ($row=null)
 as_whole ()
 get_results ()
 as_array ($field)
 as_line ($row_number=null)
 as_one ($row_number=null, $field=null)

Protected Attributes

 $sql
 $keyField = ''
 $focus = ''
 $noEmptyRow = false
 $typecast
 $singleRow = false
 $autoProtect = false
 $returnId = false
 $singleValue = false
 $connector = null
 $fields
 $where
 $groupby = ''
 $orderby = ''
 $limit = ''
 $cachedResult
 $rowCount = -1
 $affectedRows = -1
 $single_value
 $return_id
 $auto_protect
 $single_row
 $no_empty_row

Member Function Documentation

addWhere ( sql,
mode = 'AND' 
)

Add a subclause to the main WHERE clause of the query

Parameters:
string$sql
Returns:
self
as_array ( field)

Returns a single field from every line, resulting in an array of values (ie some kind of "vertical" fetching)

Note: this is different from as_whole, since only ONE value is present in each line

Deprecated:
Since:
20100216
Version:
1.0
Author:
greg
Parameters:
$fieldstring, the field to extract on each line
Returns:
array, all the values
as_line ( row_number = null)

Returns the asked line as an array

You can either ask for the next line (no parameter) or given a row number in the result.

Note: the row number is based on the result, it may not be same as the row number in the complete table

Deprecated:
Since:
3.0
Version:
1.0.1
Author:
greg
Date:
20100810 (v1.0.1) (greg) return null if the resultset is empty
Parameters:
integer$row_number(optional)
Returns:
array| null, the line or null if the resultset is empty
as_one ( row_number = null,
field = null 
)

Return one value from the asked field of the asked line

Deprecated:
Since:
3.0
Version:
1.0.3
Author:
greg
Date:
20100620 (v1.0.1) (greg) made parameters optional (no "field" means first field)
20100630 (v1.0.2) (greg) object's focus is used if "$field" parameter is empty
20100810 (v1.0.3) (greg) return null if the resultset is empty
Parameters:
integer$row_number(optional)
string$fieldfield name (optional)
Returns:
string | null
as_whole ( )

Returns all lines from the result as a big array of arrays

Deprecated:
Since:
20100216 (v1.0) (greg)
20100428 (v1.1) (greg) use the focus parameter; use the smart key
20100607 (v1.2) (greg) renamed compact to focus, use the noEmptyRow/single_line parameters
Version:
1.1
Author:
greg
Returns:
array, all the lines as arrays
asArray ( field)

Returns a single field from every line, resulting in an array of values (ie some kind of "vertical" fetching)

Note: this is different from as_whole, since only ONE value is present in each line

Since:
20100216
Version:
1.0.1
Date:
20110816 (v1.0.1) (greg) added a count field
Author:
greg
Parameters:
$fieldstring, the field to extract on each line
Returns:
array, all the values
asLine ( row_number = null)

Returns the asked line as an array

You can either ask for the next line (no parameter) or given a row number in the result.

Note: the row number is based on the result, it may not be same as the row number in the complete table

Since:
3.0
Version:
1.0.1
Author:
greg
Date:
20100810 (v1.0.1) (greg) return null if the resultset is empty
Parameters:
integer$row_number(optional) - NOT USED ANYMORE
Returns:
array| null, the line or null if the resultset is empty
asOne ( row_number = null,
field = null 
)

Return one value from the asked field of the asked line

Since:
3.0
Version:
1.0.4
Author:
greg
Date:
20100620 (v1.0.1) (greg) made parameters optional (no "field" means first field)
20100630 (v1.0.2) (greg) object's focus is used if "$field" parameter is empty
20100810 (v1.0.3) (greg) return null if the resultset is empty
20110908 (v1.0.4) (greg) fixed a bug when dealing with an empty result line
Parameters:
integer$row_number(optional)
string$fieldfield name (optional)
Returns:
string | null
asWhole ( )

Returns all lines from the result as a big array of arrays

Since:
20100216 (v1.0) (greg)
20100428 (v1.1) (greg) use the focus parameter; use the smart key
20100607 (v1.2) (greg) renamed compact to focus, use the noEmptyRow/single_line parameters
Version:
1.1
Author:
greg
Returns:
array, all the lines as arrays
build ( parameters = null)

Build the query based on the private sql and the parameters

Since:
20100216
20100428 (v1.0.1) (greg) use sql() instead of sql
Date:
20100630 (v1.0.2) (greg) use array_compact to avoid null values
Version:
1.0.2
Author:
greg
Parameters:
$parameters(optional)array, the parameters to inject into the query
Returns:
string, the sql query string
checkParameters ( &$  parameters = null)

Allows daughter classes to check the parameters array before the query is sent

Parameters:
$parametersarray, the unprotected parameters
Returns:
boolean true is it's ok to sent, false otherwise
checkResults ( &$  results = null)

Allows daughter classes to check the results array before it's sent back

Parameters:
$parametersarray, the unprotected results
Returns:
boolean true is it's ok to sent, false otherwise
connector ( connector = null)

Get and/or set the actual connector instance

Note: can only be set if it was not set before

Parameters:
PHPDS_dbConnector | string$connector
Returns:
PHPDS_dbConnector
construct ( )

Constructor

Reimplemented from PHPDS_dependant.

count ( )

Return the number of lines in a result

Since:
20100216
Version:
2.0
Date:
20110816 (v2.0) (greg) changed not use a call to the connector since a PDO might give a wrong result
Author:
greg
Returns:
integer, the number of rows, or -1 if it cannot be evaluated
debugInstance ( domain = null)

The private debug instance of this object (with domain selection)

Reimplemented from PHPDS_dependant.

extra_build ( parameters = null)

Construct the extra part of the query (WHERE ... GROUP BY ... ORDER BY...) Doesn't change $this->sql

Deprecated:
Parameters:
array$parameters
Returns:
string (sql)
Version:
1.0
Author:
greg
extraBuild ( parameters = null)

Construct the extra part of the query (WHERE ... GROUP BY ... ORDER BY...) Doesn't change $this->sql

Parameters:
array$parameters
Returns:
string (sql)
Version:
1.0
Author:
greg
get_key ( row = null)

Try to figure out which is the key field.

Deprecated:
Parameters:
array$row,asample row to study
Returns:
string (or null), the key field name
Version:
1.0
Author:
greg
get_results ( )

Deal with all special cases (i.e flags) regarding how results should be returned

The special cases handled are these (in order of precedence):

  • returnId (instead of the actual result, last_id is returned)
  • single_value (only the first value is returned as a scalar)
  • singleRow (the first row is returned as a an one-dimension array)

Cell-specific handling is done elsewhere

In the absence of special case, the whole result is returned as an array of arrays (by calling as_whole() )

Deprecated:
Version:
1.1
Date:
20100610 (greg) (v1.0) added, based on Jason's work
20100617 (jason) (v1.0.1) added support for "string" setting
20100620 (greg) (v1.0.2) cleaned up using class methods
20100708 (greg) (v1.1) clean up with definitive API
Returns:
usually an array, although can be false, or int for an ID
getKey ( row = null)

Try to figure out which is the key field.

Parameters:
array$row,asample row to study
Returns:
string (or null), the key field name
Version:
1.0
Author:
greg
getResults ( )

Deal with all special cases (i.e flags) regarding how results should be returned

The special cases handled are these (in order of precedence):

  • returnId (instead of the actual result, lastId is returned)
  • singleValue (only the first value is returned as a scalar)
  • singleRow (the first row is returned as a an one-dimension array)

Cell-specific handling is done elsewhere

In the absence of special case, the whole result is returned as an array of arrays (by calling as_whole() )

Version:
1.1.1
Date:
20100610 (greg) (v1.0) added, based on Jason's work
20100617 (jason) (v1.0.1) added support for "string" setting
20100620 (greg) (v1.0.2) cleaned up using class methods
20100708 (greg) (v1.1) clean up with definitive API
20110812 (greg) (v1.1.1) removed special "empty" case since only MySQL supports it
Returns:
usually an array, although can be false, or int for an ID
invoke ( parameters = null)

The usual process of a query: check the parameters, send the query to the server, check the results

Return the results as an array (for SELECT queries), true for other successfull queries, false on failure

Version:
1.1.1
Date:
20100709 (greg) (v1.1.1) changed is_resource() to !empty() because it may return something else
Parameters:
mixed$parameters
Returns:
array or boolean
limit ( limit)

Limits query.

Parameters:
int$limit
preBuild ( )

If the fields list has been set, construct the SELECT statement (or else do nothing)

Version:
1.0.1
Author:
greg
Date:
20100628 (v1.0.1) (greg) the build sql string replaces the obejct's sql field, instead of being appended
Returns:
nothing
protect_array ( array $  a)

Protect a array of strings from possible hacker (i.e. escape possible harmfull chars)

Deprecated:
Since:
20100216
Version:
1.0
Author:
greg
Parameters:
$aarray, the strings to protect
Returns:
array, the same string but safe
protectArray ( array $  a,
quote = '' 
)

Protect a array of strings from possible hacker (i.e. escape possible harmfull chars)

Since:
20100216
Version:
1.1
Date:
20111010 (v1.1) (greg) added "quote" parameter
Author:
greg
Parameters:
$aarray, the strings to protect
$quotestring, the quotes to add to each non-numerical scalar value
Returns:
array, the same string but safe
protectString ( string)

Protect a strings from possible hacker (i.e. escape possible harmfull chars)

Since:
20101109
Version:
1.0
Author:
Jason
Parameters:
stringthe strings to protect
Returns:
string the same string but safe
query ( parameters = null)

Build and send the query to the database

Since:
20100219
Version:
1.0.3
Date:
20110216 (greg) (v1.0.3) added a log of the sql + the class name
20110731 (greg) altered to use $this->querySQL
Author:
greg
Parameters:
mixed$parameters(optional)array, the parameters to inject into the query
Returns:
void
queryDebug ( sql)

FIrephp-specific debug display of the query

Parameters:
string$sql
querySQL ( sql)

Direclty send the query to the database

Since:
20110731
Version:
1.0
Date:
20110731 (greg) added based on old $this->query
Author:
greg
Parameters:
string$sql,thesql request
Returns:
void
rows ( parameters = null)

Build a query combination of columns and rows specifically designed to write rows of data to the database.

Since:
20100226
20100226
Version:
1.0.0
Parameters:
arrayHolds columns in the order they need to be written.
sql ( sql = null)

Get/set actual sql string.

You may want to override this to alter the sql string as whole, and/or build it from various sources. Note this is only the first part of the query (SELECT ... FROM ...), NOT including WHERE, GROUP BY, ORDER BY, LIMIT

Parameters:
string$sql(optional) if given, stored into the object's sql string
Returns:
string the sql text
Version:
1.0
Author:
greg
total ( )
typeCast ( values,
key = null 
)
Parameters:
<type>$values
<type>$key
Returns:
<type>

Field Documentation

$affectedRows = -1 [protected]
$auto_protect [protected]
$autoProtect = false [protected]
$cachedResult [protected]
$connector = null [protected]
$fields [protected]
$focus = '' [protected]
$groupby = '' [protected]
$keyField = '' [protected]
$limit = '' [protected]
$no_empty_row [protected]
$noEmptyRow = false [protected]
$orderby = '' [protected]
$return_id [protected]
$returnId = false [protected]
$rowCount = -1 [protected]
$single_row [protected]
$single_value [protected]
$singleRow = false [protected]
$singleValue = false [protected]
$sql [protected]
$typecast [protected]
$where [protected]

The documentation for this class was generated from the following files:
 All Data Structures Files Functions Variables Enumerations