نمایش نتایج 1 تا 1 از 1

نام تاپیک: تبدیل کدهای php5 به php7

  1. #1
    کاربر دائمی
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    نهاوند (استان همدان)
    پست
    103

    Question تبدیل کدهای php5 به php7

    سلام دوستان
    من یه اسکریپتی دارم که توابع اون با 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;

    ممنون میشم راهنمایی کنید.
    آخرین ویرایش به وسیله Ali_Sedaghat : پنج شنبه 03 خرداد 1403 در 13:23 عصر

تاپیک های مشابه

  1. مقاله: بررسی تغییرات و ویژگی‌های جدید در php7
    نوشته شده توسط مهرداد سیف زاده در بخش PHP
    پاسخ: 6
    آخرین پست: جمعه 06 فروردین 1400, 08:10 صبح
  2. php7
    نوشته شده توسط khadem1386 در بخش PHP
    پاسخ: 0
    آخرین پست: سه شنبه 11 دی 1397, 13:28 عصر
  3. سؤال: مهاجرت به php7
    نوشته شده توسط asa.66 در بخش CodeIgniter
    پاسخ: 3
    آخرین پست: یک شنبه 02 آبان 1395, 20:18 عصر
  4. اتصال شی گرایی با my sqli در php7
    نوشته شده توسط imanasp در بخش PHP
    پاسخ: 3
    آخرین پست: جمعه 05 شهریور 1395, 14:38 عصر
  5. PHP7 و YII2
    نوشته شده توسط desatir7316 در بخش Yii Framework
    پاسخ: 1
    آخرین پست: جمعه 13 آذر 1394, 21:19 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •