[line 50]
The methods PEAR DB uses to interact with PHP's mysqli extension for interacting with MySQL databases
This is for MySQL versions 4.1 and above. Requires PHP 5.
Note that persistent connections no longer exist.
These methods overload the ones declared in DB_common.
$connection =
[line 126]
The raw database connection created by PHP
$dbsyntax = 'mysqli'
[line 64]
The database syntax variant to be used (db2, access, etc.), if any
$dsn = array()
[line 132]
The DSN information for connecting to a database
$errorcode_map = array(
1004 => DB_ERROR_CANNOT_CREATE,
1005 => DB_ERROR_CANNOT_CREATE,
1006 => DB_ERROR_CANNOT_CREATE,
1007 => DB_ERROR_ALREADY_EXISTS,
1008 => DB_ERROR_CANNOT_DROP,
1022 => DB_ERROR_ALREADY_EXISTS,
1044 => DB_ERROR_ACCESS_VIOLATION,
1046 => DB_ERROR_NODBSELECTED,
1048 => DB_ERROR_CONSTRAINT,
1049 => DB_ERROR_NOSUCHDB,
1050 => DB_ERROR_ALREADY_EXISTS,
1051 => DB_ERROR_NOSUCHTABLE,
1054 => DB_ERROR_NOSUCHFIELD,
1061 => DB_ERROR_ALREADY_EXISTS,
1062 => DB_ERROR_ALREADY_EXISTS,
1064 => DB_ERROR_SYNTAX,
1091 => DB_ERROR_NOT_FOUND,
1100 => DB_ERROR_NOT_LOCKED,
1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
1142 => DB_ERROR_ACCESS_VIOLATION,
1146 => DB_ERROR_NOSUCHTABLE,
1216 => DB_ERROR_CONSTRAINT,
1217 => DB_ERROR_CONSTRAINT,
1356 => DB_ERROR_DIVZERO,
1451 => DB_ERROR_CONSTRAINT,
1452 => DB_ERROR_CONSTRAINT,
)
[line 93]
A mapping of native error codes to DB error codes
$features = array(
'limit' => 'alter',
'new_link' => false,
'numrows' => true,
'pconnect' => false,
'prepare' => false,
'ssl' => true,
'transactions' => true,
)
[line 79]
The capabilities of this DB implementation
The 'new_link' element contains the PHP version that first provided new_link support for this DBMS. Contains false if it's unsupported.
Meaning of the 'limit' element:
- 'emulate' = emulate with fetch row by number
- 'alter' = alter the query
- false = skip rows
$mysqli_flags = array(
MYSQLI_NOT_NULL_FLAG => 'not_null',
MYSQLI_PRI_KEY_FLAG => 'primary_key',
MYSQLI_UNIQUE_KEY_FLAG => 'unique_key',
MYSQLI_MULTIPLE_KEY_FLAG => 'multiple_key',
MYSQLI_BLOB_FLAG => 'blob',
MYSQLI_UNSIGNED_FLAG => 'unsigned',
MYSQLI_ZEROFILL_FLAG => 'zerofill',
MYSQLI_AUTO_INCREMENT_FLAG => 'auto_increment',
MYSQLI_TIMESTAMP_FLAG => 'timestamp',
MYSQLI_SET_FLAG => 'set',
// MYSQLI_NUM_FLAG => 'numeric', // unnecessary
// MYSQLI_PART_KEY_FLAG => 'multiple_key', // duplicatvie
MYSQLI_GROUP_FLAG => 'group_by'
)
[line 169]
Array for converting MYSQLI_*_FLAG constants to text values
- Since: Property available since Release 1.6.5
- Access: public
$mysqli_types = array(
MYSQLI_TYPE_DECIMAL => 'decimal',
MYSQLI_TYPE_TINY => 'tinyint',
MYSQLI_TYPE_SHORT => 'int',
MYSQLI_TYPE_LONG => 'int',
MYSQLI_TYPE_FLOAT => 'float',
MYSQLI_TYPE_DOUBLE => 'double',
// MYSQLI_TYPE_NULL => 'DEFAULT NULL', // let flags handle it
MYSQLI_TYPE_TIMESTAMP => 'timestamp',
MYSQLI_TYPE_LONGLONG => 'bigint',
MYSQLI_TYPE_INT24 => 'mediumint',
MYSQLI_TYPE_DATE => 'date',
MYSQLI_TYPE_TIME => 'time',
MYSQLI_TYPE_DATETIME => 'datetime',
MYSQLI_TYPE_YEAR => 'year',
MYSQLI_TYPE_NEWDATE => 'date',
MYSQLI_TYPE_ENUM => 'enum',
MYSQLI_TYPE_SET => 'set',
MYSQLI_TYPE_TINY_BLOB => 'tinyblob',
MYSQLI_TYPE_MEDIUM_BLOB => 'mediumblob',
MYSQLI_TYPE_LONG_BLOB => 'longblob',
MYSQLI_TYPE_BLOB => 'blob',
MYSQLI_TYPE_VAR_STRING => 'varchar',
MYSQLI_TYPE_STRING => 'char',
MYSQLI_TYPE_GEOMETRY => 'geometry',
/* These constants are conditionally compiled in ext/mysqli, so we'll
* define them by number rather than constant. */
16 => 'bit',
246 => 'decimal',
)
[line 191]
Array for converting MYSQLI_TYPE_* constants to text values
- Since: Property available since Release 1.6.5
- Access: public
$phptype = 'mysqli'
[line 58]
The DB driver type (mysql, oci8, odbc, etc.)
__construct (Constructor) [line 231]
This constructor calls
parent::__construct()
Overrides
DB_common::__construct() (This constructor calls
$this->PEAR('DB_Error'))
affectedRows [line 638]
Determines the number of rows affected by a data maniuplation query
- is returned for queries that don't manipulate data.
- Return: the number of rows. A DB_Error object on failure.
Overrides
DB_common::affectedRows() (Determines the number of rows affected by a data maniuplation query)
autoCommit [line 568]
int autoCommit(
[bool
$onoff = false])
Enables or disables automatic commits
- Return: DB_OK on success. A DB_Error object if the driver doesn't support auto-committing transactions.
Overrides
DB_common::autoCommit() (Enables or disables automatic commits)
Parameters:
bool
$onoff
—
true turns it on, false turns it off
commit [line 584]
Commits the current transaction
- Return: DB_OK on success. A DB_Error object on failure.
Overrides
DB_common::commit() (Commits the current transaction)
connect [line 285]
int connect(
array
$dsn, [bool
$persistent = false])
Connect to the database server, log in and open the database
Don't call this method directly. Use DB::connect() instead.
PEAR DB's mysqli driver supports the following extra DSN options:
- key The path to the key file.
- cert The path to the certificate file.
- ca The path to the certificate authority file.
- capath The path to a directory that contains trusted SSL
CA certificates in pem format.
- cipher The list of allowable ciphers for SSL encryption.
Example of how to connect using SSL:
require_once 'DB.php';
$dsn = array(
'phptype' => 'mysqli',
'username' => 'someuser',
'password' => 'apasswd',
'hostspec' => 'localhost',
'database' => 'thedb',
'key' => 'client-key.pem',
'cert' => 'client-cert.pem',
'ca' => 'cacert.pem',
'capath' => '/path/to/ca/dir',
'cipher' => 'AES',
);
$options = array(
'ssl' => true,
);
if (PEAR::isError($db)) {
die($db->getMessage());
}
- Return: DB_OK on success. A DB_Error object on failure.
Parameters:
array
$dsn
—
the data source name
bool
$persistent
—
should the connection be persistent?
createSequence [line 749]
int createSequence(
string
$seq_name)
Creates a new sequence
Overrides
DB_common::createSequence() (Creates a new sequence)
Parameters:
string
$seq_name
—
name of the new sequence
disconnect [line 361]
Disconnects from the database server
- Return: TRUE on success, FALSE on failure
dropSequence [line 775]
int dropSequence(
string
$seq_name)
Deletes a sequence
Overrides
DB_common::dropSequence() (Deletes a sequence)
Parameters:
string
$seq_name
—
name of the sequence to be deleted
errorNative [line 943]
Gets the DBMS' native error code produced by the last query
- Return: the DBMS' error code
Overrides
DB_common::errorNative() (Gets the DBMS' native error code produced by the last query)
escapeSimple [line 867]
string escapeSimple(
string
$str)
Escapes a string according to the current DBMS's standards
Overrides
DB_common::escapeSimple() (Escapes a string according to the current DBMS's standards)
Parameters:
string
$str
—
the string to be escaped
fetchInto [line 450]
mixed fetchInto(
resource
$result,
&$arr, int
$fetchmode, [int
$rownum = null], array
$arr)
Places a row from the result set into the given array
Formating of the array and the data therein are configurable. See DB_result::fetchInto() for more information.
This method is not meant to be called directly. Use DB_result::fetchInto() instead. It can't be declared "protected" because DB_result is a separate object.
- Return: DB_OK on success, NULL when the end of a result set is reached or on failure
- See: DB_result::fetchInto()
Parameters:
resource
$result
—
the query result resource
array
$arr
—
the referenced array to put the data in
int
$fetchmode
—
how the resulting array should be indexed
int
$rownum
—
the row number to fetch (0 = first row)
&$arr
—
freeResult [line 498]
bool freeResult(
resource
$result)
Deletes the result set and frees the memory occupied by the result set
This method is not meant to be called directly. Use DB_result::free() instead. It can't be declared "protected" because DB_result is a separate object.
Parameters:
resource
$result
—
PHP's query result resource
getSpecialQuery [line 1075]
string getSpecialQuery(
string
$type)
Obtains the query string needed for listing a given type of objects
- Return: the SQL query string or null if the driver doesn't support the object type requested
- See: DB_common::getListOf()
- Access: protected
Overrides
DB_common::getSpecialQuery() (Obtains the query string needed for listing a given type of objects)
Parameters:
string
$type
—
the kind of objects you want to retrieve
modifyLimitQuery [line 891]
string modifyLimitQuery(
string
$query, int
$from, int
$count, [mixed
$params = array()])
Adds LIMIT clauses to a query string according to current DBMS standards
- Return: the query string with LIMIT clauses added
- Access: protected
Overrides
DB_common::modifyLimitQuery() (Adds LIMIT clauses to a query string according to current DBMS standards)
Parameters:
string
$query
—
the query to modify
int
$from
—
the row to start to fetching (0 = the first row)
int
$count
—
the numbers of rows to fetch
mixed
$params
—
array, string or numeric data to be used in execution of the statement. Quantity of items passed must match quantity of placeholders in query: meaning 1 placeholder for non-array parameters or 1 placeholder per array element.
mysqliRaiseError [line 915]
object the mysqliRaiseError(
[int
$errno = null])
Produces a DB_Error object regarding the current problem
Parameters:
int
$errno
—
if the error is being manually raised pass a DB_ERROR* constant here. If this isn't passed the error information gathered from the DBMS.
nextId [line 663]
int nextId(
string
$seq_name, [boolean
$ondemand = true])
Returns the next free id in a sequence
Overrides
DB_common::nextId() (Returns the next free id in a sequence)
Parameters:
string
$seq_name
—
name of the sequence
boolean
$ondemand
—
when true, the seqence is automatically created if it does not exist
nextResult [line 422]
false nextResult(
resource
$result)
Move the internal mysql result pointer to the next available result.
This method has not been implemented yet.
Parameters:
resource
$result
—
a valid sql result resource
numCols [line 523]
int numCols(
resource
$result)
Gets the number of columns in a result set
This method is not meant to be called directly. Use DB_result::numCols() instead. It can't be declared "protected" because DB_result is a separate object.
Parameters:
resource
$result
—
PHP's query result resource
numRows [line 548]
int numRows(
resource
$result)
Gets the number of rows in a result set
This method is not meant to be called directly. Use DB_result::numRows() instead. It can't be declared "protected" because DB_result is a separate object.
Overrides
DB_common::numRows() (Determines the number of rows in a query result)
Parameters:
resource
$result
—
PHP's query result resource
quoteIdentifier [line 849]
string quoteIdentifier(
string
$str)
Quotes a string so it can be safely used as a table or column name (WARNING: using names that require this is a REALLY BAD IDEA)
WARNING: Older versions of MySQL can't handle the backtick character (`) in table or column names.
Overrides
DB_common::quoteIdentifier() (Quotes a string so it can be safely used as a table or column name)
Parameters:
string
$str
—
identifier name to be quoted
rollback [line 610]
Reverts the current transaction
- Return: DB_OK on success. A DB_Error object on failure.
Overrides
DB_common::rollback() (Reverts the current transaction)
simpleQuery [line 380]
mixed simpleQuery(
string
$query)
Sends a query to the database server
- Return: + a PHP result resrouce for successful SELECT queries
- the DB_OK constant for other successful queries
- a DB_Error object on failure
Parameters:
string
$query
—
the SQL query string
tableInfo [line 966]
array tableInfo(
object|string
$result, [int
$mode = null])
Returns information about a table or a result set
- Return: an associative array with the information requested. A DB_Error object on failure.
- See: DB_common::setOption()
Overrides
DB_common::tableInfo() (Returns information about a table or a result set)
Parameters:
object|string
$result
—
DB_result object from a query or a string containing the name of a table. While this also accepts a query result resource identifier, this behavior is deprecated.
int
$mode
—
a valid tableInfo mode