PDA

View Full Version : تبدیل کدهای php5 به php7



Ali_Sedaghat
پنج شنبه 03 خرداد 1403, 08:51 صبح
سلام دوستان
من یه اسکریپتی دارم که توابع اون با php5 نوشته شده که می خوام به php7 تبدیل شون کنم.
در یک فایلش دچار مشکل شدم که مربوط به کلاس بانک اطلاعاتی هست.
کدهای اصلیش رو این جا قرار میدم:


<?php
/** A PHP class to access MySQL database with convenient methods
* in an object oriented way, and with a powerful debug system.\n
* Licence: LGPL \n
* Web site: http://slaout.linux62.org/
* @version 1.0
* @author S&eacute;bastien Lao&ucirc;t (slaout@linux62.org)
*/
class DB
{
/** Put this variable to true if you want ALL queries to be debugged by default:
*/
var $defaultDebug = false;

/** INTERNAL: The start time, in miliseconds.
*/
var $mtStart;
/** INTERNAL: The number of executed queries.
*/
var $nbQueries;
/** INTERNAL: The last result ressource of a query().
*/
var $lastResult;

/** Connect to a MySQL database to be able to use the methods below.
*/
function DB($base, $server, $user, $pass)
{
$this->mtStart = $this->getMicroTime();
$this->nbQueries = 0;
$this->lastResult = NULL;
mysql_connect($server, $user, $pass) or die('Server Error');
mysql_select_db($base) or die('Database Error');
mysql_query("SET NAMES utf8");
}

/** Query the database.
* @param $query The query.
* @param $debug If true, it output the query and the resulting table.
* @return The result of the query, to use with fetchNextObject().
*/
function query($query, $debug = -1)
{
$this->nbQueries++;
$this->lastResult = mysql_query($query) or $this->debugAndDie($query);

$this->debug($debug, $query, $this->lastResult);

return $this->lastResult;
}
} // class DB
?>


کد رو به این شکل نوشتم اما نمی دونم در تابع query چه طوری به دیتابیس وصل بشم.


<?php
/** A PHP class to access MySQL database with convenient methods
* in an object oriented way, and with a powerful debug system.\n
* Licence: LGPL \n
* Web site: http://slaout.linux62.org/
* @version 1.0
* @author S&eacute;bastien Lao&ucirc;t (slaout@linux62.org)
*/
class DB
{
/** Put this variable to true if you want ALL queries to be debugged by default:
*/
var $defaultDebug = false;

/** INTERNAL: The start time, in miliseconds.
*/
var $mtStart;
/** INTERNAL: The number of executed queries.
*/
var $nbQueries;
/** INTERNAL: The last result ressource of a query().
*/
var $lastResult;

/** Connect to a MySQL database to be able to use the methods below.
*/
function DB($base, $server, $user, $pass)
{
$this->mtStart = $this->getMicroTime();
$this->nbQueries = 0;
$this->lastResult = NULL;
$db_link = mysqli_connect($server, $user, $pass, $base) or die('Server Error');
mysqli_query($db_link, "SET NAMES utf8");
}

/** Query the database.
* @param $query The query.
* @param $debug If true, it output the query and the resulting table.
* @return The result of the query, to use with fetchNextObject().
*/
function query($query, $debug = -1)
{
$this->nbQueries++;
$this->lastResult = mysqli_query($this->db_link, $query) or $this->debugAndDie($query);

$this->debug($debug, $query, $this->lastResult);

return $this->lastResult;
}
} // class DB
?>



توابع زیادی در داخل کلاس قرار داره که من فقط به دو تابع از اون اشاره کردم.
مشکل من اینه که در تابع mysqli_query که دو تا آرگومان می خواد، در آرگومان اولش که مربوط به متغیر دیتابیس مشکل دارم و نمی دونم این متغیر رو چه طور به تابع دوم معرفی کنم و با ارور بر روی خط 44 که مربوط به تابع mysqli_query هست مواجه میشم.
در متن خطا میگه که آرگومان اول تابع mysqli_quey مقدار Null داره.
البته ناگفته نمونه که بعد از تعریف کلاس و جایی که متغیرها تعریف شدن این کد رو هم قرار دادم ولی بازم نشد که نشد.


var $db_link;

ممنون میشم راهنمایی کنید.