Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
11,394 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
class MainWPChildDB | ||
{ | ||
//Support old & new versions of wordpress (3.9+) | ||
public static function use_mysqli() | ||
{ | ||
/** @var $wpdb wpdb */ | ||
if (!function_exists( 'mysqli_connect' ) ) return false; | ||
|
||
global $wpdb; | ||
return ($wpdb->dbh instanceof mysqli); | ||
} | ||
|
||
public static function _query($query, $link) | ||
{ | ||
if (self::use_mysqli()) | ||
{ | ||
return mysqli_query($link, $query); | ||
} | ||
else | ||
{ | ||
return mysql_query($query, $link); | ||
} | ||
} | ||
|
||
public static function fetch_array($result) | ||
{ | ||
if (self::use_mysqli()) | ||
{ | ||
return mysqli_fetch_array($result, MYSQLI_ASSOC); | ||
} | ||
else | ||
{ | ||
return mysql_fetch_array($result, MYSQL_ASSOC); | ||
} | ||
} | ||
|
||
public static function num_rows($result) | ||
{ | ||
if (self::use_mysqli()) | ||
{ | ||
return mysqli_num_rows($result); | ||
} | ||
else | ||
{ | ||
return mysql_num_rows($result); | ||
} | ||
} | ||
|
||
public static function connect($host, $user, $pass) | ||
{ | ||
if (self::use_mysqli()) | ||
{ | ||
return mysqli_connect($host, $user, $pass); | ||
} | ||
else | ||
{ | ||
return mysql_connect($host, $user, $pass); | ||
} | ||
} | ||
|
||
public static function select_db($db) | ||
{ | ||
if (self::use_mysqli()) | ||
{ | ||
/** @var $wpdb wpdb */ | ||
global $wpdb; | ||
|
||
return mysqli_select_db($wpdb->dbh, $db); | ||
} | ||
else | ||
{ | ||
return mysql_select_db($db); | ||
} | ||
} | ||
|
||
public static function error() | ||
{ | ||
if (self::use_mysqli()) | ||
{ | ||
/** @var $wpdb wpdb */ | ||
global $wpdb; | ||
|
||
return mysqli_error($wpdb->dbh); | ||
} | ||
else | ||
{ | ||
return mysql_error(); | ||
} | ||
} | ||
|
||
public static function real_escape_string($value) | ||
{ | ||
/** @var $wpdb wpdb */ | ||
global $wpdb; | ||
|
||
if (self::use_mysqli()) | ||
{ | ||
return mysqli_real_escape_string($wpdb->dbh, $value); | ||
} | ||
else | ||
{ | ||
return mysql_real_escape_string($value, $wpdb->dbh); | ||
} | ||
} | ||
|
||
public static function is_result($result) | ||
{ | ||
if (self::use_mysqli()) | ||
{ | ||
return ($result instanceof mysqli_result); | ||
} | ||
else | ||
{ | ||
return is_resource($result); | ||
} | ||
} | ||
} |
Oops, something went wrong.