PHP 클래스 LudicrousDB, ludicrousdb

상속: extends wpdb
파일 보기 프로젝트 열기: stuttter/ludicrousdb

공개 프로퍼티들

프로퍼티 타입 설명
$check_tcp_responsiveness Whether to check with fsockopen prior to mysql_connect
$db_connections The log of db connections made and the time each one took
$dbh resource The current MySQL link resource
$dbh2host Lookup array (dbhname => host:port)
$dbhs array Associative array (dbhname => dbh) for established MySQL connections
$default_lag_threshold Maximum lag in seconds. Set null to disable. Requires callbacks
$last_found_rows_result resource After any SQL_CALC_FOUND_ROWS query, the query "SELECT FOUND_ROWS()" is sent and the MySQL result resource stored here. The next query for FOUND_ROWS() will retrieve this. We do this to prevent any intervening queries from making FOUND_ROWS() inaccessible. You may prevent this by adding "NO_SELECT_FOUND_ROWS" in a comment
$last_table string The last table that was queried
$last_used_server The last server used and the database name selected
$ludicrous_callbacks Optional directory of callbacks to determine datasets from queries
$ludicrous_servers The multi-dimensional array of datasets and servers
$ludicrous_tables Optional directory of tables and their datasets
$max_connections The maximum number of db links to keep open. The least-recently used link will be closed when the number of links exceeds this
$open_connections The list of unclosed connections sorted by LRU
$persistent Whether to use mysql_pconnect instead of mysql_connect
$save_backtrace Whether to save debug_backtrace in save_query_callback. You may wish to disable this, e.g. when tracing out-of-memory problems.
$save_queries boolean Whether to store queries in an array. Useful for debugging and profiling
$save_query_callback Custom callback to save debug info in $this->queries
$srtm Otherwise it is an array of written tables
$used_servers Lookup array (dbhname => (server, db name) ) for re-selecting the db when a link is re-used

보호된 프로퍼티들

프로퍼티 타입 설명
$reconnect_retries integer The number of times to retry reconnecting before dying

공개 메소드들

메소드 설명
__construct ( $args = null ) Gets ready to make database connections
_real_escape ( $string ) * Force addslashes() for the escapes
add_callback ( $callback, $group = 'dataset' ) Add a callback to a group of callbacks
add_database ( array $db = [] ) Add the connection parameters for a database
add_table ( $dataset, $table ) Specify the dataset where a table is found
check_connection ( boolean $allow_bail = true, $dbh_or_table = false ) : boolean | void Check that the connection to the database is still up. If not, try to reconnect
check_database_version ( false | string | resource $dbh_or_table = false ) : WP_Error Whether or not MySQL database is at least the required minimum version.
check_lag ( ) : integer Check lag
check_tcp_responsiveness ( $host, $port, $float_timeout ) : boolean Check the responsiveness of a TCP/IP daemon
close ( false | string | resource $dbh_or_table = false ) : boolean Closes the current database connection
db_connect ( $query = '' ) : resource Figure out which db server should handle the query, and connect to it
db_version ( false | string | resource $dbh_or_table = false ) : false | string The database version number
disconnect ( string $dbhname ) Disconnect and remove connection from open connections list
flush ( ) Kill cached query results
get_caller ( ) : string Get the name of the function that called wpdb()
get_lag ( ) : integer Run lag callbacks and return current lag
get_lag_cache ( ) : integer Run lag cache callbacks and return current lag
has_cap ( string $db_cap, false | string | resource $dbh_or_table = false ) : boolean Generic function to determine if a database supports a particular feature The additional argument allows the caller to check a specific database
init_charset ( ) Sets $this->charset and $this->collate
is_write_query ( $q ) : boolean Determine the likelihood that this query could alter anything
query ( string $query ) : integer Basic query. See docs for more details
run_callbacks ( $group, $args = null ) Callbacks are executed in the order in which they are registered until one of them returns something other than null
select ( string $db, false | string | resource $dbh_or_table = false ) Selects a database using the current database connection
send_reads_to_masters ( ) Set a flag to prevent reading from slaves which might be lagging after a write
set_charset ( resource $dbh, string $charset = null, string $collate = null ) Sets the connection's character set
set_sql_mode ( array $modes = [], false | string | resource $dbh_or_table = false ) Change the current SQL mode, and ensure its WordPress compatibility
supports_collation ( false | string | resource $dbh_or_table = false ) : boolean This function is called when WordPress is generating the table schema to determine whether or not the current database supports or needs the collation statements

보호된 메소드들

메소드 설명
_do_query ( string $query, boolean $dbh_or_table = false ) Internal function to perform the mysql_query() call
get_table_charset ( string $table ) : mixed Retrieves a tables character set.
load_col_info ( ) Load the column metadata from the last query.
single_db_connect ( string $dbhname, string $host, string $user, string $password ) : boolean | mysqli | resource Connect selected database
strip_invalid_text_using_db ( string $string, string $charset ) : mixed Given a string, a character set and a table, ask the DB to check the string encoding.
tcp_cache_get ( string $key ) : mixed Get cached up/down value of previous TCP response
tcp_cache_set ( string $key, string $value ) : boolean Set cached up/down value of current TCP response
tcp_get_cache_expiration ( ) : integer Get the number of seconds TCP response is good for
tcp_get_cache_key ( string $host, string $port ) : string Get the cache key used for TCP responses

비공개 메소드들

메소드 설명
dbh_type_check ( $dbh ) : boolean
get_db_object ( false | string | resource $dbh_or_table = false ) Get the db connection object

메소드 상세

__construct() 공개 메소드

Gets ready to make database connections
public __construct ( $args = null )

_do_query() 보호된 메소드

Internal function to perform the mysql_query() call
또한 보기: wpdb::query()
protected _do_query ( string $query, boolean $dbh_or_table = false )
$query string The query to run.
$dbh_or_table boolean

_real_escape() 공개 메소드

LudicrousDB makes connections when a query is made which is why we can't use mysql_real_escape_string() for escapes This is also the reason why we don't allow certain charsets. See set_charset().
public _real_escape ( $string )

add_callback() 공개 메소드

The default group is 'dataset', used to examine queries & determine dataset
public add_callback ( $callback, $group = 'dataset' )

add_database() 공개 메소드

Add the connection parameters for a database
public add_database ( array $db = [] )
$db array

add_table() 공개 메소드

Specify the dataset where a table is found
public add_table ( $dataset, $table )

check_connection() 공개 메소드

If this function is unable to reconnect, it will forcibly die, or if after the the template_redirect hook has been fired, return false instead If $allow_bail is false, the lack of database connection will need to be handled manually
public check_connection ( boolean $allow_bail = true, $dbh_or_table = false ) : boolean | void
$allow_bail boolean Optional. Allows the function to bail. Default true.
리턴 boolean | void True if the connection is up.

check_database_version() 공개 메소드

The additional argument allows the caller to check a specific database
public check_database_version ( false | string | resource $dbh_or_table = false ) : WP_Error
$dbh_or_table false | string | resource the database (the current database, the database housing the specified table, or the database of the MySQL resource)
리턴 WP_Error

check_lag() 공개 메소드

Check lag
부터: 2.1.0
public check_lag ( ) : integer
리턴 integer

check_tcp_responsiveness() 공개 메소드

Check the responsiveness of a TCP/IP daemon
public check_tcp_responsiveness ( $host, $port, $float_timeout ) : boolean
리턴 boolean true when $host:$post responds within $float_timeout seconds, else false

close() 공개 메소드

Closes the current database connection
public close ( false | string | resource $dbh_or_table = false ) : boolean
$dbh_or_table false | string | resource the database (the current database, the database housing the specified table, or the database of the MySQL resource)
리턴 boolean True if the connection was successfully closed, false if it wasn't, or the connection doesn't exist.

db_connect() 공개 메소드

Figure out which db server should handle the query, and connect to it
public db_connect ( $query = '' ) : resource
리턴 resource MySQL database connection

db_version() 공개 메소드

The database version number
public db_version ( false | string | resource $dbh_or_table = false ) : false | string
$dbh_or_table false | string | resource the database (the current database, the database housing the specified table, or the database of the MySQL resource)
리턴 false | string false on failure, version number on success

disconnect() 공개 메소드

Disconnect and remove connection from open connections list
public disconnect ( string $dbhname )
$dbhname string

flush() 공개 메소드

Kill cached query results
public flush ( )

get_caller() 공개 메소드

Get the name of the function that called wpdb()
public get_caller ( ) : string
리턴 string the name of the calling function

get_lag() 공개 메소드

Run lag callbacks and return current lag
부터: 2.1.0
public get_lag ( ) : integer
리턴 integer

get_lag_cache() 공개 메소드

Run lag cache callbacks and return current lag
부터: 2.1.0
public get_lag_cache ( ) : integer
리턴 integer

get_table_charset() 보호된 메소드

NOTE: This must be called after LudicrousDB::db_connect, so that wpdb::dbh is set correctly
protected get_table_charset ( string $table ) : mixed
$table string Table name
리턴 mixed The table character set, or WP_Error if we couldn't find it

has_cap() 공개 메소드

Generic function to determine if a database supports a particular feature The additional argument allows the caller to check a specific database
public has_cap ( string $db_cap, false | string | resource $dbh_or_table = false ) : boolean
$db_cap string the feature
$dbh_or_table false | string | resource the database (the current database, the database housing the specified table, or the database of the MySQL resource)
리턴 boolean

init_charset() 공개 메소드

Sets $this->charset and $this->collate
public init_charset ( )

is_write_query() 공개 메소드

Determine the likelihood that this query could alter anything
public is_write_query ( $q ) : boolean
리턴 boolean

load_col_info() 보호된 메소드

Load the column metadata from the last query.
protected load_col_info ( )

query() 공개 메소드

Basic query. See docs for more details
public query ( string $query ) : integer
$query string
리턴 integer number of rows

run_callbacks() 공개 메소드

Callbacks are executed in the order in which they are registered until one of them returns something other than null
public run_callbacks ( $group, $args = null )

select() 공개 메소드

The database name will be changed based on the current database connection. On failure, the execution will bail and display an DB error
public select ( string $db, false | string | resource $dbh_or_table = false )
$db string MySQL database name
$dbh_or_table false | string | resource the database (the current database, the database housing the specified table, or the database of the MySQL resource)

send_reads_to_masters() 공개 메소드

Set a flag to prevent reading from slaves which might be lagging after a write

set_charset() 공개 메소드

Sets the connection's character set
public set_charset ( resource $dbh, string $charset = null, string $collate = null )
$dbh resource The resource given by mysql_connect
$charset string The character set (optional)
$collate string The collation (optional)

set_sql_mode() 공개 메소드

If no modes are passed, it will ensure the current MySQL server modes are compatible
public set_sql_mode ( array $modes = [], false | string | resource $dbh_or_table = false )
$modes array Optional. A list of SQL modes to set.
$dbh_or_table false | string | resource the database (the current database, the database housing the specified table, or the database of the MySQL resource)

single_db_connect() 보호된 메소드

Connect selected database
protected single_db_connect ( string $dbhname, string $host, string $user, string $password ) : boolean | mysqli | resource
$dbhname string
$host string Internet address: host:port of server on internet.
$user string Database user.
$password string Database password.
리턴 boolean | mysqli | resource

strip_invalid_text_using_db() 보호된 메소드

Classes that extend wpdb can override this function without needing to copy/paste all of wpdb::strip_invalid_text(). NOTE: This must be called after LudicrousDB::db_connect, so that wpdb::dbh is set correctly
protected strip_invalid_text_using_db ( string $string, string $charset ) : mixed
$string string String to convert
$charset string Character set to test against (uses MySQL character set names)
리턴 mixed The converted string, or a WP_Error if the conversion fails

supports_collation() 공개 메소드

The additional argument allows the caller to check a specific database
public supports_collation ( false | string | resource $dbh_or_table = false ) : boolean
$dbh_or_table false | string | resource the database (the current database, the database housing the specified table, or the database of the MySQL resource)
리턴 boolean

tcp_cache_get() 보호된 메소드

Get cached up/down value of previous TCP response
부터: 3.0.0
protected tcp_cache_get ( string $key ) : mixed
$key string Results of tcp_get_cache_key()
리턴 mixed Results of wp_cache_get()

tcp_cache_set() 보호된 메소드

Set cached up/down value of current TCP response
부터: 3.0.0
protected tcp_cache_set ( string $key, string $value ) : boolean
$key string Results of tcp_get_cache_key()
$value string "up" or "down" based on TCP response
리턴 boolean Results of wp_cache_set()

tcp_get_cache_expiration() 보호된 메소드

Get the number of seconds TCP response is good for
부터: 3.0.0
protected tcp_get_cache_expiration ( ) : integer
리턴 integer

tcp_get_cache_key() 보호된 메소드

Get the cache key used for TCP responses
부터: 3.0.0
protected tcp_get_cache_key ( string $host, string $port ) : string
$host string
$port string
리턴 string

프로퍼티 상세

$check_tcp_responsiveness 공개적으로 프로퍼티

Whether to check with fsockopen prior to mysql_connect
public $check_tcp_responsiveness

$db_connections 공개적으로 프로퍼티

The log of db connections made and the time each one took
public $db_connections

$dbh 공개적으로 프로퍼티

The current MySQL link resource
public resource $dbh
리턴 resource

$dbh2host 공개적으로 프로퍼티

Lookup array (dbhname => host:port)
public $dbh2host

$dbhs 공개적으로 프로퍼티

Associative array (dbhname => dbh) for established MySQL connections
public array $dbhs
리턴 array

$default_lag_threshold 공개적으로 프로퍼티

Maximum lag in seconds. Set null to disable. Requires callbacks
public $default_lag_threshold

$last_found_rows_result 공개적으로 프로퍼티

After any SQL_CALC_FOUND_ROWS query, the query "SELECT FOUND_ROWS()" is sent and the MySQL result resource stored here. The next query for FOUND_ROWS() will retrieve this. We do this to prevent any intervening queries from making FOUND_ROWS() inaccessible. You may prevent this by adding "NO_SELECT_FOUND_ROWS" in a comment
public resource $last_found_rows_result
리턴 resource

$last_table 공개적으로 프로퍼티

The last table that was queried
public string $last_table
리턴 string

$last_used_server 공개적으로 프로퍼티

The last server used and the database name selected
public $last_used_server

$ludicrous_callbacks 공개적으로 프로퍼티

Optional directory of callbacks to determine datasets from queries
public $ludicrous_callbacks

$ludicrous_servers 공개적으로 프로퍼티

The multi-dimensional array of datasets and servers
public $ludicrous_servers

$ludicrous_tables 공개적으로 프로퍼티

Optional directory of tables and their datasets
public $ludicrous_tables

$max_connections 공개적으로 프로퍼티

The maximum number of db links to keep open. The least-recently used link will be closed when the number of links exceeds this
public $max_connections

$open_connections 공개적으로 프로퍼티

The list of unclosed connections sorted by LRU
public $open_connections

$persistent 공개적으로 프로퍼티

Whether to use mysql_pconnect instead of mysql_connect
public $persistent

$reconnect_retries 보호되어 있는 프로퍼티

The number of times to retry reconnecting before dying
또한 보기: wpdb::check_connection()
protected int $reconnect_retries
리턴 integer

$save_backtrace 공개적으로 프로퍼티

Whether to save debug_backtrace in save_query_callback. You may wish to disable this, e.g. when tracing out-of-memory problems.
public $save_backtrace

$save_queries 공개적으로 프로퍼티

Whether to store queries in an array. Useful for debugging and profiling
public bool $save_queries
리턴 boolean

$save_query_callback 공개적으로 프로퍼티

Custom callback to save debug info in $this->queries
public $save_query_callback

$srtm 공개적으로 프로퍼티

Otherwise it is an array of written tables
public $srtm

$used_servers 공개적으로 프로퍼티

Lookup array (dbhname => (server, db name) ) for re-selecting the db when a link is re-used
public $used_servers