Skip to content
Draft
Changes from all 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
54 changes: 34 additions & 20 deletions ludicrousdb/includes/class-ludicrousdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,19 @@
*
* @since 1.0.0
*
* @param bool $allow_bail Unused. For WordPress compatibility only.

Check failure on line 688 in ludicrousdb/includes/class-ludicrousdb.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 3 spaces after parameter type; 1 found
* @param string $query Query.
*
* @return resource MySQL database connection
* @return false|mysqli MySQL database connection
*/
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 ) {

Check failure on line 698 in ludicrousdb/includes/class-ludicrousdb.php

View workflow job for this annotation

GitHub Actions / phpcs

Empty ELSEIF statement detected
// unlike WP core we can try another server if one fails
}

// Bail if empty query
if ( empty( $query ) ) {
Expand Down Expand Up @@ -1412,14 +1420,20 @@
*
* @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.
*/

Check failure on line 1429 in ludicrousdb/includes/class-ludicrousdb.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 5 spaces before asterisk; 4 found
public function select( $db, $dbh_or_table = false ) {
$dbh = $this->get_db_object( $dbh_or_table );
public function select( $db, $dbh = false, $table = false ) {

Check failure on line 1430 in ludicrousdb/includes/class-ludicrousdb.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 5 spaces before asterisk; 4 found
if ( $dbh === false ) {

Check failure on line 1431 in ludicrousdb/includes/class-ludicrousdb.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 5 spaces before asterisk; 4 found
$dbh = $this->get_db_object( $table );
} elseif ( is_string( $dbh ) ) {
// backwards-compatibility of $dbh_or_table
$dbh = $this->get_db_object( $dbh );
}

if ( ! $this->dbh_type_check( $dbh ) ) {
return false;
Expand Down Expand Up @@ -1468,17 +1482,17 @@
* 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,17 +1607,17 @@
*
* @since 1.0.0
*
* @param bool $die_on_disconnect Optional. Allows the function to die. Default true.
* @param bool $dbh_or_table Optional.
* @param bool $allow_bail Optional. Allows the function to die. Default true.
* @param false|string|mysqli|resource $dbh_or_table Optional.
* @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 );

Check failure on line 1618 in ludicrousdb/includes/class-ludicrousdb.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 25 spaces after parameter type; 3 found
// Return true if ping is successful. This is the most common case.
if (

Check failure on line 1620 in ludicrousdb/includes/class-ludicrousdb.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 23 spaces after parameter type; 1 found
$this->dbh_type_check( $dbh )
&&
mysqli_ping( $dbh )
Expand All @@ -1624,7 +1638,7 @@
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 +1660,7 @@
}

// 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 +1803,7 @@
$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 +2193,7 @@

// 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
Loading