mirror of
https://github.com/mainwp/mainwp-child.git
synced 2025-08-31 03:53:15 +08:00
[CodeFactor] Apply fixes
[ci skip] [skip ci]
This commit is contained in:
parent
fe28452590
commit
f8a0b137ef
1 changed files with 73 additions and 73 deletions
|
@ -14,32 +14,32 @@ namespace MainWP\Child;
|
|||
*/
|
||||
class MainWP_Child_DB {
|
||||
// phpcs:disable WordPress.DB.RestrictedFunctions, WordPress.DB.PreparedSQL.NotPrepared -- unprepared SQL ok, accessing the database directly to custom database functions.
|
||||
/**
|
||||
* Support old & new versions of WordPress (3.9+).
|
||||
*
|
||||
* @return bool|object Instantiated object of \mysqli.
|
||||
*/
|
||||
public static function use_mysqli() {
|
||||
/**
|
||||
* Support old & new versions of WordPress (3.9+).
|
||||
*
|
||||
* @return bool|object Instantiated object of \mysqli.
|
||||
*/
|
||||
public static function use_mysqli() {
|
||||
if ( ! function_exists( '\mysqli_connect' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var $wpdb wpdb */
|
||||
/** @var $wpdb wpdb */
|
||||
global $wpdb;
|
||||
|
||||
return ( $wpdb->dbh instanceof \mysqli );
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a mysqli query & get a result.
|
||||
*
|
||||
* @param $query An SQL query
|
||||
* @param $link A link identifier
|
||||
* @return bool|\mysqli_result|resource For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries, mysqli_query()
|
||||
* will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.
|
||||
* Returns FALSE on failure.
|
||||
*/
|
||||
public static function to_query($query, $link ) {
|
||||
/**
|
||||
* Run a mysqli query & get a result.
|
||||
*
|
||||
* @param $query An SQL query
|
||||
* @param $link A link identifier
|
||||
* @return bool|\mysqli_result|resource For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries, mysqli_query()
|
||||
* will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.
|
||||
* Returns FALSE on failure.
|
||||
*/
|
||||
public static function to_query( $query, $link ) {
|
||||
if ( self::use_mysqli() ) {
|
||||
return \mysqli_query( $link, $query );
|
||||
} else {
|
||||
|
@ -47,13 +47,13 @@ class MainWP_Child_DB {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an array.
|
||||
*
|
||||
* @param $result A result set identifier.
|
||||
* @return array|false|nul Returns an array of strings that corresponds to the fetched row, or false if there are no more rows.
|
||||
*/
|
||||
public static function fetch_array($result ) {
|
||||
/**
|
||||
* Fetch an array.
|
||||
*
|
||||
* @param $result A result set identifier.
|
||||
* @return array|false|nul Returns an array of strings that corresponds to the fetched row, or false if there are no more rows.
|
||||
*/
|
||||
public static function fetch_array( $result ) {
|
||||
if ( self::use_mysqli() ) {
|
||||
return \mysqli_fetch_array( $result, MYSQLI_ASSOC );
|
||||
} else {
|
||||
|
@ -61,13 +61,13 @@ class MainWP_Child_DB {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of rows.
|
||||
*
|
||||
* @param $result A result set identifier returned.
|
||||
* @return false|int Returns number of rows in the result set.
|
||||
*/
|
||||
public static function num_rows($result ) {
|
||||
/**
|
||||
* Count the number of rows.
|
||||
*
|
||||
* @param $result A result set identifier returned.
|
||||
* @return false|int Returns number of rows in the result set.
|
||||
*/
|
||||
public static function num_rows( $result ) {
|
||||
if ( self::use_mysqli() ) {
|
||||
return \mysqli_num_rows( $result );
|
||||
} else {
|
||||
|
@ -75,15 +75,15 @@ class MainWP_Child_DB {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to Child Site Database.
|
||||
*
|
||||
* @param $host Can be either a host name or an IP address.
|
||||
* @param $user The MySQL user name.
|
||||
* @param $pass The MySQL user password.
|
||||
* @return false|\mysqli|resource object which represents the connection to a MySQL Server or false if an error occurred.
|
||||
*/
|
||||
public static function connect($host, $user, $pass ) {
|
||||
/**
|
||||
* Connect to Child Site Database.
|
||||
*
|
||||
* @param $host Can be either a host name or an IP address.
|
||||
* @param $user The MySQL user name.
|
||||
* @param $pass The MySQL user password.
|
||||
* @return false|\mysqli|resource object which represents the connection to a MySQL Server or false if an error occurred.
|
||||
*/
|
||||
public static function connect( $host, $user, $pass ) {
|
||||
if ( self::use_mysqli() ) {
|
||||
return \mysqli_connect( $host, $user, $pass );
|
||||
} else {
|
||||
|
@ -91,13 +91,13 @@ class MainWP_Child_DB {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select Child Site DB.
|
||||
*
|
||||
* @param $db Database name.
|
||||
* @return bool true on success or false on failure.
|
||||
*/
|
||||
public static function select_db($db ) {
|
||||
/**
|
||||
* Select Child Site DB.
|
||||
*
|
||||
* @param $db Database name.
|
||||
* @return bool true on success or false on failure.
|
||||
*/
|
||||
public static function select_db( $db ) {
|
||||
if ( self::use_mysqli() ) {
|
||||
|
||||
/** @var $wpdb wpdb */
|
||||
|
@ -109,12 +109,12 @@ class MainWP_Child_DB {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get any mysqli errors.
|
||||
*
|
||||
* @return string the error text from the last MySQL function, or '' (empty string) if no error occurred.
|
||||
*/
|
||||
public static function error() {
|
||||
/**
|
||||
* Get any mysqli errors.
|
||||
*
|
||||
* @return string the error text from the last MySQL function, or '' (empty string) if no error occurred.
|
||||
*/
|
||||
public static function error() {
|
||||
if ( self::use_mysqli() ) {
|
||||
|
||||
/** @var $wpdb wpdb */
|
||||
|
@ -126,13 +126,13 @@ class MainWP_Child_DB {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a given string.
|
||||
*
|
||||
* @param $value The string to be escaped. Characters encoded are NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.
|
||||
* @return false|string the escaped string, or false on error.
|
||||
*/
|
||||
public static function real_escape_string($value ) {
|
||||
/**
|
||||
* Escape a given string.
|
||||
*
|
||||
* @param $value The string to be escaped. Characters encoded are NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.
|
||||
* @return false|string the escaped string, or false on error.
|
||||
*/
|
||||
public static function real_escape_string( $value ) {
|
||||
|
||||
/** @var $wpdb wpdb */
|
||||
global $wpdb;
|
||||
|
@ -144,13 +144,13 @@ class MainWP_Child_DB {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if $result is an Instantiated object of \mysqli.
|
||||
*
|
||||
* @param $result Instantiated object of \mysqli.
|
||||
* @return mysqli_result|bool Instantiated object of \mysqli, true if var is a resource, false otherwise.
|
||||
*/
|
||||
public static function is_result($result ) {
|
||||
/**
|
||||
* Check if $result is an Instantiated object of \mysqli.
|
||||
*
|
||||
* @param $result Instantiated object of \mysqli.
|
||||
* @return mysqli_result|bool Instantiated object of \mysqli, true if var is a resource, false otherwise.
|
||||
*/
|
||||
public static function is_result( $result ) {
|
||||
if ( self::use_mysqli() ) {
|
||||
return ( $result instanceof mysqli_result );
|
||||
} else {
|
||||
|
@ -158,12 +158,12 @@ class MainWP_Child_DB {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the DB.
|
||||
*
|
||||
* @return int|mixed Size of the DB or false on failure.
|
||||
*/
|
||||
public static function get_size() {
|
||||
/**
|
||||
* Get the size of the DB.
|
||||
*
|
||||
* @return int|mixed Size of the DB or false on failure.
|
||||
*/
|
||||
public static function get_size() {
|
||||
/** @var $wpdb wpdb */
|
||||
global $wpdb;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue