Skip to content
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions ludicrousdb/includes/class-ludicrousdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,20 @@ public function run_callbacks( $group = '', $args = null ) {
*
* @since 1.0.0
*
* @param bool $allow_bail Unused. For WP compat only.
Comment thread
JJJ marked this conversation as resolved.
Outdated
Comment thread
JJJ marked this conversation as resolved.
Outdated
* @param string $query Query.
*
* @return resource MySQL database connection
Comment thread
JJJ marked this conversation as resolved.
Outdated
*/
public function db_connect( $query = '' ) {
public function db_connect( $allow_bail = null, $query = '' ) {
if ( is_string( $allow_bail ) && $query === '' ) {
$query = $allow_bail;
// for reference only, not used, since this is generally not what we want here
// $allow_bail = $this->die_on_disconnect;
} elseif ( $allow_bail === null ) {
// unlike WP core we can try another server if one fails
// $allow_bail = $this->die_on_disconnect;
Comment thread
JJJ marked this conversation as resolved.
Outdated
}

// Bail if empty query
if ( empty( $query ) ) {
Expand Down Expand Up @@ -1412,14 +1421,20 @@ public function set_sql_mode( $modes = array(), $dbh_or_table = false ) {
*
* @since 1.0.0
*
* @param string $db MySQL database name.
* @param false|string|mysqli|resource $dbh_or_table Optional. The database. One of:
* - the current database
* - the database housing the specified table
* - the database of the MySQL resource
* @param string $db MySQL database name.
* @param false|mysqli|resource $dbh Optional. The database. One of:
* - the current database
* - the database housing the specified table
* - the database of the MySQL resource
Comment thread
JJJ marked this conversation as resolved.
* @param false|string $table Optional. The table name. Only used if $dbh is false
Comment thread
JJJ marked this conversation as resolved.
Outdated
*/
public function select( $db, $dbh_or_table = false ) {
$dbh = $this->get_db_object( $dbh_or_table );
public function select( $db, $dbh = false, $table = false ) {
if ( $dbh === false ) {
$dbh = $this->get_db_object( $table );
} elseif ( is_string( $dbh ) ) {
// backwards-compat of $dbh_or_table
Comment thread
JJJ marked this conversation as resolved.
Outdated
$dbh = $this->get_db_object( $dbh );
}

if ( ! $this->dbh_type_check( $dbh ) ) {
return false;
Expand Down Expand Up @@ -1468,17 +1483,17 @@ protected function load_col_info() {
* See set_charset().
*
* @since 1.0.0
* @param string $to_escape String to escape.
* @param string $data String to escape.
*/
public function _real_escape( $to_escape = '' ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
public function _real_escape( $data = '' ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore

// Bail if not a scalar
if ( ! is_scalar( $to_escape ) ) {
if ( ! is_scalar( $data ) ) {
return '';
}

// Slash the query part
$escaped = addslashes( $to_escape );
$escaped = addslashes( $data );

// Maybe use WordPress core placeholder method
if ( method_exists( $this, 'add_placeholder_escape' ) ) {
Expand Down Expand Up @@ -1593,13 +1608,13 @@ public function flush() {
*
* @since 1.0.0
*
* @param bool $die_on_disconnect Optional. Allows the function to die. Default true.
* @param bool $allow_bail Optional. Allows the function to die. Default true.
* @param bool $dbh_or_table Optional.
Comment thread
JJJ marked this conversation as resolved.
Outdated
* @param string $query Optional. Query string passed db_connect
*
* @return bool|void True if the connection is up.
*/
public function check_connection( $die_on_disconnect = true, $dbh_or_table = false, $query = '' ) {
public function check_connection( $allow_bail = true, $dbh_or_table = false, $query = '' ) {
$dbh = $this->get_db_object( $dbh_or_table );

// Return true if ping is successful. This is the most common case.
Expand All @@ -1624,7 +1639,7 @@ public function check_connection( $die_on_disconnect = true, $dbh_or_table = fal
for ( $tries = 1; $tries <= $this->reconnect_retries; $tries++ ) {

// Try to reconnect
$retry = $this->db_connect( $query );
$retry = $this->db_connect( false, $query );

// Return true if the connection is up
if ( false !== $retry ) {
Expand All @@ -1646,7 +1661,7 @@ public function check_connection( $die_on_disconnect = true, $dbh_or_table = fal
}

// Bail here if not allowed to call $this->bail()
if ( false === $die_on_disconnect ) {
if ( false === $allow_bail ) {
return false;
}

Expand Down Expand Up @@ -1789,7 +1804,7 @@ public function query( $query ) {
$elapsed = 0;

} else {
$this->dbh = $this->db_connect( $query );
$this->dbh = $this->db_connect( $this->die_on_disconnect, $query );

if ( ! $this->dbh_type_check( $this->dbh ) ) {
$this->run_query_log_callbacks( $query, $retval );
Expand Down Expand Up @@ -2179,7 +2194,7 @@ private function get_db_object( $dbh_or_table = false ) {

// Table name
} elseif ( is_string( $dbh_or_table ) ) {
$dbh = $this->db_connect( "SELECT FROM {$dbh_or_table} {$this->users}" );
$dbh = $this->db_connect( $this->die_on_disconnect, "SELECT FROM {$dbh_or_table} {$this->users}" );
}

return $dbh;
Expand Down