game/_incl_data/mysql_override.php

155 lines
3.7 KiB
PHP
Raw Permalink Normal View History

2022-12-19 20:22:19 +00:00
<?php
/**
* Make mysql_connect work like mysqli_connect for future php versions.
*
* @author Ivor Barhansky
2023-08-10 14:21:02 +00:00
* @version 0.2
2022-12-19 20:22:19 +00:00
*/
// Make sure the MySQL extension is not loaded and there is no other drop in replacement active
if (!extension_loaded('mysql') && !function_exists('mysql_connect')) {
// Validate if the MySQLi extension is present
if (!extension_loaded('mysqli')) {
trigger_error('The extension "MySQLi" is not available', E_USER_ERROR);
}
// The function name "getLinkIdentifier" will be used to return a valid link_indentifier, make it is available
if (function_exists('getLinkIdentifier')) {
trigger_error('The function name "getLinkIdentifier" is already defined, please change the function name', E_USER_ERROR);
}
// Define MySQL constants
define('MYSQL_CLIENT_COMPRESS', MYSQLI_CLIENT_COMPRESS);
define('MYSQL_CLIENT_IGNORE_SPACE', MYSQLI_CLIENT_IGNORE_SPACE);
define('MYSQL_CLIENT_INTERACTIVE', MYSQLI_CLIENT_INTERACTIVE);
define('MYSQL_CLIENT_SSL', MYSQLI_CLIENT_SSL);
define('MYSQL_ASSOC', MYSQLI_ASSOC);
define('MYSQL_NUM', MYSQLI_NUM);
define('MYSQL_BOTH', MYSQLI_BOTH);
// Will contain the link identifier
$link = null;
/**
* Get the link identifier
*
* @param mysqli $mysqli
* @return mysqli|null
*/
function getLinkIdentifier(mysqli $mysqli = null)
{
if (!$mysqli) {
global $link;
$mysqli = $link;
}
return $mysqli;
}
/**
* Open a connection to a MySQL Server
*
* @param $server
* @param $username
* @param $password
* @return mysqli|null
2022-12-30 19:03:37 +00:00
* @deprecated
2022-12-19 20:22:19 +00:00
*/
function mysql_connect($server, $username, $password, $new_link = false, $client_flags = 0)
{
global $link;
$link = mysqli_connect($server, $username, $password);
return $link;
}
/**
* @param $databaseName
* @return bool
2022-12-30 19:03:37 +00:00
* @deprecated
2022-12-19 20:22:19 +00:00
*/
function mysql_select_db($databaseName)
{
global $link;
return mysqli_select_db($link, $databaseName);
}
/**
* @param $query
* @param mysqli $mysqli
* @return bool|mysqli_result
2022-12-30 19:03:37 +00:00
* @deprecated
2022-12-19 20:22:19 +00:00
*/
function mysql_query($query, mysqli $mysqli = null)
{
return getLinkIdentifier($mysqli)->query($query);
}
/**
* @param $string
* @param mysqli $mysqli
* @return string
2022-12-30 19:03:37 +00:00
* @deprecated
2022-12-19 20:22:19 +00:00
*/
function mysql_real_escape_string($string, mysqli $mysqli = null)
{
return getLinkIdentifier($mysqli)->escape_string($string);
}
/**
* @param mysqli_result $result
* @return bool|array
2022-12-30 19:03:37 +00:00
* @deprecated
2022-12-19 20:22:19 +00:00
*/
function mysql_fetch_assoc(mysqli_result $result)
{
$result = $result->fetch_assoc();
if ($result === null) {
$result = false;
}
return $result;
}
/**
* @param mysqli_result $result
* @return bool|int
2022-12-30 19:03:37 +00:00
* @deprecated
2022-12-19 20:22:19 +00:00
*/
function mysql_num_rows(mysqli_result $result)
{
$result = $result->num_rows;
if ($result === null) {
$result = false;
}
return $result;
}
/**
* @param mysqli_result $result
* @param $result_type
* @return void
2022-12-30 19:03:37 +00:00
* @deprecated
2022-12-19 20:22:19 +00:00
*/
function mysql_fetch_array(mysqli_result $result, $result_type = MYSQL_BOTH)
{
return mysqli_fetch_array($result, $result_type);
}
/**
* Get the ID generated in the last query
*
* @param null $mysqli
* @return int|string
2022-12-30 19:03:37 +00:00
* @deprecated
2022-12-19 20:22:19 +00:00
*/
function mysql_insert_id(mysqli $mysqli = null)
{
return mysqli_insert_id(getLinkIdentifier($mysqli));
}
}