Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions classes/app.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
require_once dirname(__FILE__) . '/helper.php';

define('APP_DIR', realpath(dirname(__FILE__) . '/..'));
define('MODULE_DIR', APP_DIR . DIRECTORY_SEPARATOR . 'modules');
define('CLASS_DIR', APP_DIR . DIRECTORY_SEPARATOR . 'classes');
define('INCLUDE_DIR', APP_DIR . DIRECTORY_SEPARATOR . 'includes');
define('MODULE_DIR', APP_DIR . DIRECTORY_SEPARATOR . 'modules');
define('CLASS_DIR', APP_DIR . DIRECTORY_SEPARATOR . 'classes');
define('INCLUDE_DIR', APP_DIR . DIRECTORY_SEPARATOR . 'includes');

require_once INCLUDE_DIR . '/mysql_compat.php';

class app
{
Expand Down
6 changes: 4 additions & 2 deletions classes/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*/
class database
*/
require_once dirname(__FILE__) . '/../includes/mysql_compat.php';

class database
{

var $tablePrefix = '';
Expand Down
169 changes: 169 additions & 0 deletions includes/mysql_compat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php
if (function_exists('mysql_connect')) {
return;
}

// Define legacy fetch mode constants when missing.
if (!defined('MYSQL_ASSOC')) {
define('MYSQL_ASSOC', MYSQLI_ASSOC);
}
if (!defined('MYSQL_NUM')) {
define('MYSQL_NUM', MYSQLI_NUM);
}
if (!defined('MYSQL_BOTH')) {
define('MYSQL_BOTH', MYSQLI_BOTH);
}

if (!function_exists('get_magic_quotes_gpc')) {
function get_magic_quotes_gpc()
{
return 0;
}
}

if (!function_exists('get_magic_quotes_runtime')) {
function get_magic_quotes_runtime()
{
return 0;
}
}

if (!function_exists('set_magic_quotes_runtime')) {
function set_magic_quotes_runtime($new_value)
{
return false;
}
}

$GLOBALS['mysql_compat_last_connection'] = null;

function mysql_connect($server = null, $username = null, $password = null, $new_link = false, $client_flags = 0)
{
$link = mysqli_connect($server, $username, $password);
if ($link instanceof mysqli) {
$GLOBALS['mysql_compat_last_connection'] = $link;
}
return $link;
}

function mysql_select_db($database_name, $link_identifier = null)
{
$link = $link_identifier instanceof mysqli ? $link_identifier : mysql_compat_get_link();
if (!$link) {
return false;
}
return mysqli_select_db($link, $database_name);
}

function mysql_query($query, $link_identifier = null)
{
$link = $link_identifier instanceof mysqli ? $link_identifier : mysql_compat_get_link();
if (!$link) {
return false;
}
$result = mysqli_query($link, $query);
return $result;
}

function mysql_fetch_object($result, $class_name = 'stdClass', $params = array())
{
if (!($result instanceof mysqli_result)) {
return false;
}
return mysqli_fetch_object($result, $class_name, $params);
}

function mysql_fetch_row($result)
{
if (!($result instanceof mysqli_result)) {
return false;
}
return mysqli_fetch_row($result);
}

function mysql_fetch_assoc($result)
{
if (!($result instanceof mysqli_result)) {
return false;
}
return mysqli_fetch_assoc($result);
}

function mysql_fetch_array($result, $result_type = MYSQL_BOTH)
{
if (!($result instanceof mysqli_result)) {
return false;
}
return mysqli_fetch_array($result, $result_type);
}

function mysql_num_rows($result)
{
if (!($result instanceof mysqli_result)) {
return false;
}
return mysqli_num_rows($result);
}

function mysql_real_escape_string($unescaped_string, $link_identifier = null)
{
$link = $link_identifier instanceof mysqli ? $link_identifier : mysql_compat_get_link();
if (!$link) {
return addslashes($unescaped_string);
}
return mysqli_real_escape_string($link, (string) $unescaped_string);
}

function mysql_affected_rows($link_identifier = null)
{
$link = $link_identifier instanceof mysqli ? $link_identifier : mysql_compat_get_link();
if (!$link) {
return -1;
}
return mysqli_affected_rows($link);
}

function mysql_insert_id($link_identifier = null)
{
$link = $link_identifier instanceof mysqli ? $link_identifier : mysql_compat_get_link();
if (!$link) {
return 0;
}
return mysqli_insert_id($link);
}

function mysql_result($result, $row, $field = 0)
{
if (!($result instanceof mysqli_result)) {
return false;
}
if (!mysqli_data_seek($result, $row)) {
return false;
}
$data = mysqli_fetch_array($result, MYSQLI_BOTH);
if ($data === null || $data === false) {
return false;
}
if (is_int($field)) {
return array_key_exists($field, $data) ? $data[$field] : false;
}
return array_key_exists($field, $data) ? $data[$field] : false;
}

function mysql_error($link_identifier = null)
{
$link = $link_identifier instanceof mysqli ? $link_identifier : mysql_compat_get_link();
if (!$link) {
return mysqli_connect_error();
}
return mysqli_error($link);
}

function mysql_compat_get_link()
{
$link = $GLOBALS['mysql_compat_last_connection'] ?? null;
if ($link instanceof mysqli) {
return $link;
}
return null;
}