dbPDO_MySQL
extends dbBase
in package
Database core class for the PDO::MySQL library
Tags
Table of Contents
Properties
- $config_valid : mixed
- $connection : mixed
- $last_result : mixed
- $mysql_database : mixed
- $mysql_host : mixed
- $mysql_pass : mixed
- $mysql_port : mixed
- $mysql_prefix : mixed
- $mysql_socket : mixed
- $mysql_user : mixed
- $use_utf8 : mixed
Methods
- __construct() : true
- Connect to the database server and select the database.
- close() : mixed
- Closes the database
- connect() : object|false
- convertDatabaseToUtf8mb4() : mixed
- Converts ab utf8 database to utf8mb4
- convertTableToUtf8mb4() : bool
- Converts a utf8 table to utf8mb4 collation
- count() : int
- Counts entries in a db table
- create() : mixed
- create the database
- createTable() : array<string|int, mixed>
- fetchAssoc() : mixed
- Fetch a result row as an associative array
- fetchRow() : mixed
- Get a result row as an enumerated array
- freeResult() : mixed
- Frees the memory assiciated with a resutl
- getAffectedRows() : mixed
- Get number of affected rows in previous operation
- getClientInfo() : string
- Returns the client info
- getCollationSetClause() : string
- Gets the set clause to set the collation for tables to create
- getDBInfo() : array<string|int, mixed>
- Gets an array of database infos
- getDBName() : mixed
- returns the connected database name
- getError() : mixed
- Returns the text of the error message from previous operation
- getExpectedTables() : array<string|int, mixed>
- Gets the names of the tables expected to exist in a Zenphoto database
- getFields() : array<string|int, mixed>|false
- Gets the detail info of all fields in a table
- getFieldsNotUtf8() : bool|array<string|int, mixed>
- Gets all columns of a table are not utf8.
- getNumRows() : mixed
- Get number of rows in result
- getPermissions() : mixed
- Returns user's permissions on the database
- getPrefix() : string
- Gets the plain database table prefix
- getServerInfo() : string
- Returns the server info
- getSetClause() : contructed
- Constructs a SET clause ("SET uniqueid1='uniquevalue1', uniqueid2='uniquevalue2' ...") from an array (map) of variables and their values which identifies a unique record in the database table. Used to 'move' records. Note: does not check anything.
- getSoftware() : mixed
- report the software of the database
- getSQLmode() : mixed
- Queries the SQL session mode
- getTables() : array<string|int, mixed>
- Returns an array with the tables names of the database
- getType() : mixed
- Returns the database type (MySQL or MariaDB)
- getVersion() : int
- Gets the plain version number
- getVersionComplete() : mixed
- Gets the full version including prefixes and appendixes (as on MariaDB)
- getWhereClause() : contructed
- Constructs a WHERE clause ("WHERE uniqueid1='uniquevalue1' AND uniqueid2='uniquevalue2' ...") from an array (map) of variables and their values which identifies a unique record in the database table.
- hasTable() : bool
- Checks if a table exists in the database
- hasUtf8mb4Support() : bool
- Checks if the database support utf8mb4 or ut8mb4_520 encodings
- insertId() : mixed
- returns the insert id of the last database insert
- insertID() : mixed
- isEmptyTable() : bool
- Checks if a table has no content and/or does not exist
- isMariaDB() : bool
- Returns true if the database is MariaDB
- isTableWithUtf8Fields() : bool
- Checks if all columns of a table are utf8
- isUf8CharsetType() : array<string|int, mixed>
- Helper method that returns it a charset matches a general charset category.
- isUtf8System() : bool
- Checks if the database character set and the collation are using UTF8
- isUTF8Table() : bool
- Checks if a table itself uses an utf8 collation
- likeEscape() : string
- Escapes LIKE statements
- listFields() : mixed
- logConnectionError() : mixed
- Logs an database error to the php error_log in case the ZPCMS own debuglog functions are not yet available
- prefix() : prefixed
- Prefix a table name with a user-defined string to avoid conflicts and enclosed all in backticks This MUST be used in all database queries.
- query() : results
- The main query function. Runs the SQL on the connection and handles errors.
- queryFullArray() : results
- Runs a SQL query and returns an array of associative arrays of every row returned.
- querySingleRow() : results
- Runs a SQL query and returns an associative array of the first row.
- quote() : string
- sqlite_real_escape_string standin that insures the DB connection is passed.
- setConfig() : mixed
- Checks and sets properties for the database credentials
- setSQLmode() : mixed
- Sets the SQL session mode to empty
- show() : array<string|int, mixed>
- Wrapper method for various SHOW queries
- tableUpdate() : array<string|int, mixed>
- truncateTable() : mixed
- Deletes the content of a table
Properties
$config_valid
public
mixed
$config_valid
= \false
$connection
public
mixed
$connection
= \null
$last_result
public
mixed
$last_result
$mysql_database
public
mixed
$mysql_database
= ''
$mysql_host
public
mixed
$mysql_host
= ''
$mysql_pass
public
mixed
$mysql_pass
= ''
$mysql_port
public
mixed
$mysql_port
= 3306
$mysql_prefix
public
mixed
$mysql_prefix
= ''
$mysql_socket
public
mixed
$mysql_socket
= \null
$mysql_user
public
mixed
$mysql_user
= ''
$use_utf8
public
mixed
$use_utf8
= \false
Methods
__construct()
Connect to the database server and select the database.
public
__construct(array<string|int, mixed> $config[, bool $errorstop = true ]) : true
Parameters
- $config : array<string|int, mixed>
-
the db configuration parameters
- $errorstop : bool = true
-
set to false to omit error messages
Return values
true —if successful connection
close()
Closes the database
public
close() : mixed
connect()
public
connect() : object|false
Tags
Return values
object|falseconvertDatabaseToUtf8mb4()
Converts ab utf8 database to utf8mb4
public
convertDatabaseToUtf8mb4([bool $force_conversion = false ]) : mixed
Parameters
- $force_conversion : bool = false
-
default false so only tables that have no non utf8* columns are converted
convertTableToUtf8mb4()
Converts a utf8 table to utf8mb4 collation
public
convertTableToUtf8mb4(string $table[, bool $force_conversion = false ]) : bool
Partly adapted from WordPress' maybe_convert_table_to_utf8mb4()
Parameters
- $table : string
-
Table name including prefix
- $force_conversion : bool = false
-
default false so only tables that have no non utf8* columns are converted
Tags
Return values
boolcount()
Counts entries in a db table
public
count(string $table[, string $clause = NULL ][, string $field = "id" ]) : int
Parameters
- $table : string
-
Table name
- $clause : string = NULL
-
Where clause for the count query
- $field : string = "id"
-
Which fields to count (default: id)
Return values
intcreate()
create the database
public
create() : mixed
createTable()
public
createTable(string &$sql) : array<string|int, mixed>
Parameters
- $sql : string
Return values
array<string|int, mixed>fetchAssoc()
Fetch a result row as an associative array
public
fetchAssoc(mixed $resource) : mixed
Parameters
- $resource : mixed
fetchRow()
Get a result row as an enumerated array
public
fetchRow(mixed $result) : mixed
Parameters
- $result : mixed
freeResult()
Frees the memory assiciated with a resutl
public
freeResult(type $result) : mixed
Parameters
- $result : type
getAffectedRows()
Get number of affected rows in previous operation
public
getAffectedRows() : mixed
getClientInfo()
Returns the client info
public
getClientInfo() : string
Return values
stringgetCollationSetClause()
Gets the set clause to set the collation for tables to create
public
getCollationSetClause() : string
Return values
stringgetDBInfo()
Gets an array of database infos
public
getDBInfo(string $what) : array<string|int, mixed>
Uses the show method but always returns an array instead of false.
Parameters
- $what : string
-
'charsets' (db/server charsets used), 'collations' (db/server collations used)
Tags
Return values
array<string|int, mixed>getDBName()
returns the connected database name
public
getDBName() : mixed
getError()
Returns the text of the error message from previous operation
public
getError() : mixed
getExpectedTables()
Gets the names of the tables expected to exist in a Zenphoto database
public
getExpectedTables([string $prefix = null ]) : array<string|int, mixed>
Parameters
- $prefix : string = null
-
Null is default to use the prefix set in the current connection. In setup environment here pass the mysql prefix set in $_zp_conf_vars for further checks
Tags
Return values
array<string|int, mixed>getFields()
Gets the detail info of all fields in a table
public
getFields(string $table) : array<string|int, mixed>|false
Parameters
- $table : string
-
Name of the table to get the fields info of
Tags
Return values
array<string|int, mixed>|falsegetFieldsNotUtf8()
Gets all columns of a table are not utf8.
public
getFieldsNotUtf8(string $table[, string $check_charset = 'any' ]) : bool|array<string|int, mixed>
Returns false if no columns could be fetched, otherwise an array even if empty
Parameters
- $table : string
-
Tablename including prefix
- $check_charset : string = 'any'
-
'utf8', 'utf8mb4' or "any" for any utf8*
Tags
Return values
bool|array<string|int, mixed>getNumRows()
Get number of rows in result
public
getNumRows(mixed $result) : mixed
Parameters
- $result : mixed
getPermissions()
Returns user's permissions on the database
public
getPermissions() : mixed
getPrefix()
Gets the plain database table prefix
public
getPrefix() : string
Tags
Return values
stringgetServerInfo()
Returns the server info
public
getServerInfo() : string
Return values
stringgetSetClause()
Constructs a SET clause ("SET uniqueid1='uniquevalue1', uniqueid2='uniquevalue2' ...") from an array (map) of variables and their values which identifies a unique record in the database table. Used to 'move' records. Note: does not check anything.
public
getSetClause(string $new_unique_set) : contructed
Parameters
- $new_unique_set : string
-
what to add to the SET clause
Tags
Return values
contructed —SET cleause
getSoftware()
report the software of the database
public
getSoftware() : mixed
getSQLmode()
Queries the SQL session mode
public
getSQLmode() : mixed
getTables()
Returns an array with the tables names of the database
public
getTables() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getType()
Returns the database type (MySQL or MariaDB)
public
getType() : mixed
getVersion()
Gets the plain version number
public
getVersion() : int
Return values
intgetVersionComplete()
Gets the full version including prefixes and appendixes (as on MariaDB)
public
getVersionComplete() : mixed
Tags
getWhereClause()
Constructs a WHERE clause ("WHERE uniqueid1='uniquevalue1' AND uniqueid2='uniquevalue2' ...") from an array (map) of variables and their values which identifies a unique record in the database table.
public
getWhereClause(string $unique_set) : contructed
Parameters
- $unique_set : string
-
what to add to the WHERE clause
Tags
Return values
contructed —WHERE cleause
hasTable()
Checks if a table exists in the database
public
hasTable(string $table) : bool
Parameters
- $table : string
-
Table name without the prefix
Tags
Return values
boolhasUtf8mb4Support()
Checks if the database support utf8mb4 or ut8mb4_520 encodings
public
hasUtf8mb4Support([string $which = 'utf8mb4_520' ]) : bool
Adapted from WordPress' wpdp::has_cap()
Parameters
- $which : string = 'utf8mb4_520'
-
'utf8mb4' or 'utf8mb4_520' (default) or 'general' to check for any
Tags
Return values
boolinsertId()
returns the insert id of the last database insert
public
insertId() : mixed
insertID()
public
insertID() : mixed
isEmptyTable()
Checks if a table has no content and/or does not exist
public
isEmptyTable(string $table) : bool
Parameters
- $table : string
-
Table name without the prefix
Tags
Return values
boolisMariaDB()
Returns true if the database is MariaDB
public
isMariaDB() : bool
Return values
boolisTableWithUtf8Fields()
Checks if all columns of a table are utf8
public
isTableWithUtf8Fields(string $table[, string $check_charset = 'any' ]) : bool
Partly adapted from WordPress' maybe_convert_table_to_utf8mb4()
Parameters
- $table : string
-
Tablename including prefix
- $check_charset : string = 'any'
-
'utf8', 'utf8mb4' or "any" for any utf8*
Tags
Return values
boolisUf8CharsetType()
Helper method that returns it a charset matches a general charset category.
public
static isUf8CharsetType([string $charset = '' ][, string $check_charset = 'any' ]) : array<string|int, mixed>
Parameters
- $charset : string = ''
-
Charset to check against
- $check_charset : string = 'any'
-
'utf8', 'utf8mb4' or "any" for any utf8*
Return values
array<string|int, mixed>isUtf8System()
Checks if the database character set and the collation are using UTF8
public
isUtf8System([ $what = 'database' ][, string $check_charset = 'any' ]) : bool
Parameters
- $what : = 'database'
-
'database' or "server"
- $check_charset : string = 'any'
-
'utf8', 'utf8mb4' or "any" for any utf8*
Tags
Return values
boolisUTF8Table()
Checks if a table itself uses an utf8 collation
public
isUTF8Table(string $table[, string $check_charset = 'any' ][, bool $fieldcheck = true ]) : bool
Partly adapted from WordPress' maybe_convert_table_to_utf8mb4()
Parameters
- $table : string
-
Tablename including prefix
- $check_charset : string = 'any'
-
'utf8', 'utf8mb4' or "any" for any utf8*
- $fieldcheck : bool = true
-
Default true Table counts as utf8 if all text fields use some utf8 collation, otherwise only the table itself
Tags
Return values
boollikeEscape()
Escapes LIKE statements
public
likeEscape(string $str) : string
Parameters
- $str : string
Return values
stringlistFields()
public
listFields(mixed $table) : mixed
Parameters
- $table : mixed
Tags
logConnectionError()
Logs an database error to the php error_log in case the ZPCMS own debuglog functions are not yet available
public
static logConnectionError(string $error_msg[, bool $errorstop = false ]) : mixed
Parameters
- $error_msg : string
- $errorstop : bool = false
Tags
prefix()
Prefix a table name with a user-defined string to avoid conflicts and enclosed all in backticks This MUST be used in all database queries.
public
prefix([string $tablename = NULL ]) : prefixed
Parameters
- $tablename : string = NULL
-
name of the table
Tags
Return values
prefixed —table name
query()
The main query function. Runs the SQL on the connection and handles errors.
public
query(string $sql[, bool $errorstop = true ]) : results
Parameters
- $sql : string
-
sql code
- $errorstop : bool = true
-
set to false to supress the error message
Tags
Return values
results —of the sql statements
queryFullArray()
Runs a SQL query and returns an array of associative arrays of every row returned.
public
queryFullArray(string $sql[, bool $errorstop = true ][, string $key = NULL ]) : results
Parameters
- $sql : string
-
sql code
- $errorstop : bool = true
-
set to false to supress the error message
- $key : string = NULL
-
optional array index key
Tags
Return values
results —of the sql statements
querySingleRow()
Runs a SQL query and returns an associative array of the first row.
public
querySingleRow(string $sql[, bool $errorstop = true ]) : results
Doesn't handle multiple rows, so this should only be used for unique entries.
Parameters
- $sql : string
-
sql code
- $errorstop : bool = true
-
set to false to supress the error message
Tags
Return values
results —of the sql statements
quote()
sqlite_real_escape_string standin that insures the DB connection is passed.
public
quote(string $string[, mixed $addquote = true ]) : string
Parameters
- $string : string
- $addquote : mixed = true
Return values
stringsetConfig()
Checks and sets properties for the database credentials
public
setConfig(array<string|int, mixed> $config) : mixed
Parameters
- $config : array<string|int, mixed>
-
The config array containing database credentials
setSQLmode()
Sets the SQL session mode to empty
public
setSQLmode() : mixed
show()
Wrapper method for various SHOW queries
public
show(string $what[, string $aux = '' ]) : array<string|int, mixed>
Parameters
- $what : string
-
"table", "columns", "variables", "index"
- $aux : string = ''
Return values
array<string|int, mixed>tableUpdate()
public
tableUpdate(string &$sql) : array<string|int, mixed>
Parameters
- $sql : string
Return values
array<string|int, mixed>truncateTable()
Deletes the content of a table
public
truncateTable(string $table) : mixed
Parameters
- $table : string