Methods summary
public
|
|
public
resource|Mysqli
|
#
getLink( )
Fetches the mysql link. If it is not set, try to take it from the amysql
object. Of still not set, try to connect and take it.
Fetches the mysql link. If it is not set, try to take it from the amysql
object. Of still not set, try to connect and take it.
Returns
resource|Mysqli $link The mysql resource or Mysqli object
|
public
boolean
|
#
isMysqli( )
Checks whether mysqli is being used (as opposed to mysql)
Checks whether mysqli is being used (as opposed to mysql)
Returns
boolean
|
public
AMysql_Iterator
|
#
getIterator( )
Fetches the iterator for iterating through the results of the statement with
the set fetch mode (default is assoc). This method is automatically called due
to this class being an IteratorAggregate, so all you need to do is foreach your
$statement object.
Fetches the iterator for iterating through the results of the statement with
the set fetch mode (default is assoc). This method is automatically called due
to this class being an IteratorAggregate, so all you need to do is foreach your
$statement object.
Returns
Implementation of
|
public
AMysql_Statement
|
#
setFetchMode( mixed $fetchMode )
Sets the fetch mode for fetch() and fetchAll() Any extra parameters are
passed on to the handler for that fetch type. For example you can pass the class
name and parameters for fetchObject here.
Sets the fetch mode for fetch() and fetchAll() Any extra parameters are
passed on to the handler for that fetch type. For example you can pass the class
name and parameters for fetchObject here.
Parameters
- $fetchMode
mixed $fetchMode The fetch mode. Use the AMysql_Abstract constants.
Returns
|
public
AMysql_Statement
|
#
execute( mixed $binds = array () )
Executes a prepared statement, optionally accepting binds for replacing
placeholders.
Executes a prepared statement, optionally accepting binds for replacing
placeholders.
Parameters
- $binds
mixed $binds (Optional) The binds for the placeholders. This library supports names
and unnames placeholders. To use unnamed placeholders, use question marks (?) as
placeholders. A bind's key should be the index of the question mark. If $binds
is not an array, it is casted to one. To use named placeholders, the
placeholders must start with a non-alphanumeric, non-128+ character. If the key
starts with an alphanumeric or 128+ character, the placeholder that is searched
to be replaced will be the key prepended by a colon (:). Here are examples for
what keys will replace what placeholders for the value: :key: => :key: :key
=> :key key => :key key: => :key: !key => !key élet => :élet
All values are escaped and are automatically surrounded by apostrophes if
needed. Do NOT add apostrophes around the string values as encapsulating for a
mysql string.
Returns
See
|
public
|
#
getSql( string $prepared = null )
The sql string built up by the different preparing methods (prepare, select,
insert etc.) is returned, having the placeholders being replaced by their binded
values. You can debug what the final SQL string would be by calling this
method.
The sql string built up by the different preparing methods (prepare, select,
insert etc.) is returned, having the placeholders being replaced by their binded
values. You can debug what the final SQL string would be by calling this
method.
Parameters
- $prepared
string $prepared (Optional) Use this prepared string instead of the one set.
|
public
string
|
|
protected
string
|
|
public
AMysql_Statement
|
#
prepare( string $sql )
Prepares an SQL string for binding and execution. Use of this method is not
recommended externally. Use the AMysql class's prepare method instead which
returns a new AMysql_Statement instance.
Prepares an SQL string for binding and execution. Use of this method is not
recommended externally. Use the AMysql class's prepare method instead which
returns a new AMysql_Statement instance.
Parameters
- $sql
string $sql The SQL string to prepare.
Returns
|
public
AMysql_Statement
|
#
query( string $sql, array $binds = array () )
Prepares a statement and executes it with the given binds.
Prepares a statement and executes it with the given binds.
Parameters
- $sql
string $sql The SQL string to prepare.
- $binds
array $binds @see $this->execute()
Returns
See
|
protected
AMysql_Statement
|
#
_query( string $sql )
Performs the actual query on the database with the given SQL string, making
no further modifications on it.
Performs the actual query on the database with the given SQL string, making
no further modifications on it.
Parameters
- $sql
string $sql The SQL string.
Returns
Throws
|
public
AMysql_Statement
|
#
freeResults( )
Frees the mysql result resource.
Frees the mysql result resource.
Returns
|
public
array
|
#
fetchAll( )
Returns all the results with each row in the format of that specified by the
fetch mode.
Returns all the results with each row in the format of that specified by the
fetch mode.
Returns
array
See
|
public
mixed
|
#
fetch( )
Returns one row in the format specified by the fetch mode.
Returns one row in the format specified by the fetch mode.
Returns
mixed Usually array. Can also be FALSE if there are no more rows. If
AMysql_Abstract::FETCH_OBJECT is the fetch mode, then an object would be
returned.
See
|
public
array|false
|
#
fetchAssoc( )
Fetches one row with column names as the keys.
Fetches one row with column names as the keys.
Returns
array|false
|
public
<Associative
|
#
fetchAllAssoc( integer|string|boolean $keyColumn = false )
Fetches all rows and returns them as an array of associative arrays. The
outer array is numerically indexed by default, but can be indexed by a field
value.
Fetches all rows and returns them as an array of associative arrays. The
outer array is numerically indexed by default, but can be indexed by a field
value.
Parameters
- $keyColumn
integer|string|boolean $keyColumn (Optional) If a string, the cell of the given field will be the key
for its row, so the result will not be an array numerically indexed from 0 in
order. This value can also be an integer, specifying the index of the field with
the key.
Returns
<Associative result array>[]
|
public
array|false
|
#
fetchRow( )
Fetches the next row with column names as numeric indices. Returns FALSE if
there are no more rows.
Fetches the next row with column names as numeric indices. Returns FALSE if
there are no more rows.
Returns
array|false
|
public
array|false
|
|
public
array|false
|
#
fetchArray( )
Fetches the next row with column names and their indexes as keys.
Fetches the next row with column names and their indexes as keys.
Returns
array|false
|
public
string|integer|false
|
#
result( integer $row = 0, integer|string $field = 0 )
Returns the result of the given row and field. A warning is issued if the
result on the given row and column does not exist.
Returns the result of the given row and field. A warning is issued if the
result on the given row and column does not exist.
Parameters
- $row
integer $row (Optional) The row number.
- $field
integer|string $field (Optional) The field number or name.
Returns
string|integer|false
|
public
mixed
|
#
resultDefault( mixed $default, integer $row = 0, integer $field = 0 )
Returns the result of the given row and field, or the given value if the row
doesn't exist
Returns the result of the given row and field, or the given value if the row
doesn't exist
Parameters
- $default
mixed $default The value to return if the field is not found.
- $row
integer $row (Optional) The row number.
- $field
integer $field (Optional) The field.
Returns
mixed
|
public
mixed
|
#
resultNull( integer $row = 0, integer $field = 0 )
Returns the result of the given row and field, or null if the row doesn't
exist
Returns the result of the given row and field, or null if the row doesn't
exist
Parameters
- $row
integer $row (Optional) The row number.
- $field
integer $field (Optional) The field.
Returns
mixed
|
public
integer
|
#
resultInt( integer $row = 0, integer $field = 0 )
Returns the result of the given row and field as an integer. 0, if that
result doesn't exist.
Returns the result of the given row and field as an integer. 0, if that
result doesn't exist.
Parameters
- $row
integer $row (Optional) The row number.
- $field
integer $field (Optional) The field.
Returns
integer
|
public
array
|
#
fetchPairs( mixed $keyColumn = 0, mixed $valueColumn = 1 )
Returns an array of scalar values, where the keys are the values of the key
column specified, and the values are the values of the value column
specified.
Returns an array of scalar values, where the keys are the values of the key
column specified, and the values are the values of the value column
specified.
Parameters
- $keyColumn
mixed $keyColumn (Optional) column number or string for the keys. Default: 0.
- $valueColumn
mixed $valueColumn (Optional) column number or string for the values. Default: 1.
Returns
array
|
public
|
#
pairUp( mixed $keyColumn = 0, mixed $valueColumn = 1 )
|
public
array
|
#
fetchAllColumn( mixed $column = 0 )
Returns all values of a specified column as an array.
Returns all values of a specified column as an array.
Parameters
- $column
mixed $column (Optional) column number or string for the values. Default: 0.
Returns
array
|
public
array
|
#
fetchAllColumns( string|integer $keyColumn = false )
Fetches all rows and returns them as an array of columns containing an array
of values. Works simalarly to fetchAllAssoc(), but with the resulting array
transposed.
Fetches all rows and returns them as an array of columns containing an array
of values. Works simalarly to fetchAllAssoc(), but with the resulting array
transposed.
e.g. [ 'id' => ['1', '2'], 'val' => ['val1', 'val2'] ]
Parameters
- $keyColumn
string|integer $keyColumn When building an array of arrays (list of values for that column) if
this value is given, the indexes of the inner array will be equal to the value
of the column in the row equivalent of data. Typically you want to choose the
primary key. e.g. if $keyColumn is 'id', the example changes to: [ 'id' =>
['1' => '1', '2' => '2'], 'val' => [ '1' => 'val1', '2' => 'val2'
] ]
Returns
array
|
public
object
|
#
fetchObject( string $className = 'stdClass', array $params = array() )
Fetches the next row as an object.
Fetches the next row as an object.
Parameters
- $className
string $className (Optional) The class to use. Default is stdClass.
- $params
array $params (Optional) The params to pass to the object.
Returns
object
|
public
integer
|
#
affectedRows( )
Returns the number of affected rows.
Returns the number of affected rows.
Returns
integer
|
public
integer|false
|
#
numRows( )
Returns the number of rows selected, or FALSE on failure.
Returns the number of rows selected, or FALSE on failure.
Returns
integer|false
|
public
|
#
throwException( )
Throws an AMysqlException for the last mysql error. For internal use (if even
used).
Throws an AMysqlException for the last mysql error. For internal use (if even
used).
Throws
|
public
string
|
#
escapeIdentifier( string $columnName, string $as = null )
Escapes an identifier and puts it between identifier quotes.
Escapes an identifier and puts it between identifier quotes.
Parameters
- $columnName
string $identifier The identifier
- $as
string $qc The quote character. Default: `
Returns
string The escaped identifier.
|
public
AMysql_Statement
|
#
appendPrepare( string $sql )
Appends a string to the prepared string.
Appends a string to the prepared string.
Parameters
- $sql
string $sql The string to append.
Returns
|
public
AMysql_Statement
|
#
bindValue( mixed $key, mixed $val )
Binds a value to the sql string.
Binds a value to the sql string.
Parameters
- $key
mixed $key If an integer, then the given index question mark will be replaced. If a
string, then then, if it starts with an alphanumberic or 128+ ascii character,
then a colon plus the string given will be replaced, otherwise the given string
literally will be replaced. Example: if the string is foo then :foo will be
replaced. if the string is !foo then !foo will be replaced if the string is
:foo: then :foo: will be replaced. Note: don't worry about keys that have a
common beginning. If foo and fool are set, :fool will not be replaced with the
value given for foo.
- $val
mixed $val Bind this value for replacing the mark defined by $key. The value is
escaped depeding on its type, apostrophes included, so do not add apostrophes in
your prepared sqls.
Returns
|
public
AMysql_Statement
|
#
bindParam( mixed $key, mixed & $val )
The same as $this->bindValue(), except that $val is binded by reference,
meaning its value is extracted on execute.
The same as $this->bindValue(), except that $val is binded by reference,
meaning its value is extracted on execute.
Parameters
Returns
See
|
public
AMysql_Statement
|
#
setBinds( array $binds )
Sets the binds binding question marks or named binds to values.
Sets the binds binding question marks or named binds to values.
Parameters
- $binds
array $binds The binds.
Returns
|
public
AMysql_Statement
|
#
addBinds( array $binds )
Merges an array of binds with the ones already set. Only use for named
parameters!
Merges an array of binds with the ones already set. Only use for named
parameters!
Parameters
- $binds
array $binds The binds.
Returns
|
public
string
|
#
buildColumnsValues( array $data )
Builds a columns list with values as a string. Can be an array of
column-value pairs (2D for one row), can be an array of array of key-value pairs
(3D for multiple rows), or can be an array with column names as the keys, each
value being an array of values (3D for multiple rows).
Builds a columns list with values as a string. Can be an array of
column-value pairs (2D for one row), can be an array of array of key-value pairs
(3D for multiple rows), or can be an array with column names as the keys, each
value being an array of values (3D for multiple rows).
e.g. (col1 , col2 ) VALUES ('col1val1', 'col1val2'),
('col2val1', 'col2val2')
Parameters
- $data
array $data @see $this->insertReplace()
Returns
string
|
public
string
|
#
buildSet( array $data )
Puts together a string that is to be placed after a SET statement. i.e.
column1 = 'value', int_col = 3
Puts together a string that is to be placed after a SET statement. i.e.
column1 = 'value', int_col = 3
Parameters
- $data
array $data Keys are column names, values are the values unescaped
Returns
string
|
public
AMysql_Statement
|
#
update( string $tableName, array $data, string $where )
Prepares a mysql UPDATE unexecuted. By execution, have the placeholders of
the WHERE statement binded. It is rather recommended to use
AMysql_Abstract::update() instead, which lets you also bind the values in one
call and it returns the success of the query.
Prepares a mysql UPDATE unexecuted. By execution, have the placeholders of
the WHERE statement binded. It is rather recommended to use
AMysql_Abstract::update() instead, which lets you also bind the values in one
call and it returns the success of the query.
Parameters
- $tableName
string $tableName The table name.
- $data
array $data The array of data changes. A one-dimensional array with keys as column
names and values as their values.
- $where
string $where An SQL substring of the WHERE clause.
Returns
|
public
AMysql_Statement
|
#
insertReplace( string $type, string $tableName, array $data )
Prepares a mysql INSERT or REPLACE unexecuted. After this, you should just
call $this->execute(). It is rather recommended to use
AMysql_Abstract::insert() instead, which returns the last inserted id
already.
Prepares a mysql INSERT or REPLACE unexecuted. After this, you should just
call $this->execute(). It is rather recommended to use
AMysql_Abstract::insert() instead, which returns the last inserted id
already.
Parameters
- $type
string $type "$type INTO..." (INSERT, INSERT IGNORE, REPLACE) etc.
- $tableName
string $tableName The table name.
- $data
array $data A one or two-dimensional array. 1D: an associative array of keys as column
names and values as their values. This inserts one row. 2D numeric: A numeric
array where each value is an associative array with column-value pairs. Each
outer, numeric value represents a row of data. 2D associative: An associative
array where the keys are the columns, the values are numerical arrays, where
each value represents the value for the new row of that key.
Returns
|
public
AMysql_Statement
|
#
insert( string $tableName, array $data )
Performs an INSERT.
Parameters
- $tableName
string $tableName
- $data
array $data
Returns
See
$this->insertReplace
|
public
AMysql_Statement
|
#
replace( string $tableName, array $data )
Performs a REPLACE.
Parameters
- $tableName
string $tableName
- $data
array $data
Returns
See
$this->insertReplace
|
public
AMysql_Statement
|
#
delete( string $tableName, string $where )
Prepares a mysql DELETE unexecuted. By execution, have the placeholders of
the WHERE statement binded. It is rather recommended to use
AMysql_Abstract::delete() instead, which lets you also bind the values in one
call and it returns the success of the query.
Prepares a mysql DELETE unexecuted. By execution, have the placeholders of
the WHERE statement binded. It is rather recommended to use
AMysql_Abstract::delete() instead, which lets you also bind the values in one
call and it returns the success of the query.
Parameters
- $tableName
string $tableName The table name.
- $where
string $where An SQL substring of the WHERE clause.
Returns
See
|
public
integer|false
|
#
insertId( )
Returns the last insert id
Returns the last insert id
Returns
integer|false
|
public
|
|
public
|
#
__set( mixed $name, mixed $value )
|
public
integer
|
#
count( )
Returns the number of rows in the result.
Returns the number of rows in the result.
Returns
integer
Throws
Implementation of
|
public
|
#
reportErrorException( ErrorException $ex )
Handle an ErrorException thrown with the help of
$this->errorHandlerCallback. For now, just suppress the error. For internal
use.
Handle an ErrorException thrown with the help of
$this->errorHandlerCallback. For now, just suppress the error. For internal
use.
Parameters
|
public
|
#
errorHandlerCallback( integer $errno, string $errstr, string $errfile = null, integer $errline = null, array $errcontext = null )
Changes warnings into exceptions. For internal use. Mainly for handling
warnings generated by mysql functions/methods.
Changes warnings into exceptions. For internal use. Mainly for handling
warnings generated by mysql functions/methods.
Parameters
- $errno
integer $errno
- $errstr
string $errstr
- $errfile
string $errfile
- $errline
integer $errline
- $errcontext
array $errcontext
Throws
|
protected
|
#
handleError( string $msg, integer $code, string $query )
handleError
Parameters
- $msg
string $msg
- $code
integer $code
- $query
string $query
Throws
|
protected
|
|