1. <legend id='72o18'><style id='72o18'><dir id='72o18'><q id='72o18'></q></dir></style></legend>
      <i id='72o18'><tr id='72o18'><dt id='72o18'><q id='72o18'><span id='72o18'><b id='72o18'><form id='72o18'><ins id='72o18'></ins><ul id='72o18'></ul><sub id='72o18'></sub></form><legend id='72o18'></legend><bdo id='72o18'><pre id='72o18'><center id='72o18'></center></pre></bdo></b><th id='72o18'></th></span></q></dt></tr></i><div id='72o18'><tfoot id='72o18'></tfoot><dl id='72o18'><fieldset id='72o18'></fieldset></dl></div>
          <bdo id='72o18'></bdo><ul id='72o18'></ul>

        <small id='72o18'></small><noframes id='72o18'>

        <tfoot id='72o18'></tfoot>

      1. 弃用的 MySql 函数

        时间:2023-07-30
          <tfoot id='1QTZK'></tfoot>
        1. <legend id='1QTZK'><style id='1QTZK'><dir id='1QTZK'><q id='1QTZK'></q></dir></style></legend>

            <i id='1QTZK'><tr id='1QTZK'><dt id='1QTZK'><q id='1QTZK'><span id='1QTZK'><b id='1QTZK'><form id='1QTZK'><ins id='1QTZK'></ins><ul id='1QTZK'></ul><sub id='1QTZK'></sub></form><legend id='1QTZK'></legend><bdo id='1QTZK'><pre id='1QTZK'><center id='1QTZK'></center></pre></bdo></b><th id='1QTZK'></th></span></q></dt></tr></i><div id='1QTZK'><tfoot id='1QTZK'></tfoot><dl id='1QTZK'><fieldset id='1QTZK'></fieldset></dl></div>
              <tbody id='1QTZK'></tbody>
              <bdo id='1QTZK'></bdo><ul id='1QTZK'></ul>

                <small id='1QTZK'></small><noframes id='1QTZK'>

                • 本文介绍了弃用的 MySql 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  Php 不会在 一些 MySql 函数中推广即将到来的日子.

                  Php is not going to promote some MySql functions in upcoming days.

                  PHP 手册中有一些关于清除不推荐使用的函数的示例.但例如;当我在下面的代码中用 mysqli_query 替换 mysql_query 时不起作用.Notepad++ 也将它们视为由我自己定义的函数.所有示例均使用 PHP 手册中的 OOP.我需要一个不使用面向对象编程的示例.

                  There is some examples about cleaning deprecated functions in PHP manual. But for example; when i replace mysql_query with mysqli_query in code below doesn't work. Also Notepad++ treats them like functions which is defined by myself. All examples are using OOP in PHP manual. I need an example without using object orianted programing.

                  谁能告诉我如何从不推荐使用的 mysql 函数中清除我的代码?

                  Can someone tell me that how can i clean my code from deprecated mysql functions?

                  function db_connect_select() 
                  {
                          $connection = @mysql_connect(MYSQL_HOSTNAME, USERNAME_SELECT, PASSWORD);
                  
                          if (!$connection)
                          {
                            return false; 
                          }
                  
                          if (!mysql_select_db(DATABASE))
                          {
                            return false; 
                          }
                  
                          mysql_query("SET NAMES UTF8");
                  
                          return $connection;    
                  }
                  
                  function db_result_to_array($result) 
                  {
                      $res_array = array();
                  
                      for ($count = 0; $row = mysql_fetch_array($result); $count++)
                      {
                        $res_array[$count] = $row;    
                      }
                      return $res_array;
                  }
                  
                  
                  function select_top_tags()
                  {
                      $connection = db_connect_select();
                  
                      $query = 'SELECT * FROM top_tags ORDER BY tag_name ASC';
                  
                      $result = db_result_to_array(mysql_query($query));
                  
                      if(mysql_ping($connection))
                      {
                          mysql_close($connection); 
                      } 
                  
                      return $result; 
                  }
                  

                  推荐答案

                  这毫无意义.
                  单纯的机械更换是没有用的.

                  It will just make no sense.
                  A mere mechanical replacement will do no good.

                  你必须明白,它不是旧函数本身,而是不鼓励使用它们的旧方法.

                  因此,如果您想保持当前代码不变 - 只需保留它.
                  手册中的红框并不那么可怕,而且这些功能实际上会引发弃用级别错误的版本尚未发布.
                  所以,在你遇到任何不便之前,你还有 3-4 年的时间.即便如此,关闭弃用级别的错误也是一个运行时设置的问题.

                  So, if you want to keep your current code as is - just keep it.
                  A red box in the manual is not that scary, and the version in which these functions are actually would raise a deprecated-level error is not out yet.
                  So, you have a 3-4 years ahead, before you will encounter whatever inconvenience. And even then to turn off deprecated-level errors is a matter of one runtime setting.

                  但是如果你想编写更好的代码 - 你必须使用 OOP 方式和 PDOstrong>(我可以向你保证,OOP 不是可怕的.虽然它在编写时需要一些知识,但使用现成的类非常容易.与熟悉的函数唯一的区别是一点点-> 东西.没什么大不了的)

                  But if you want to write the better code - you have to use OOP way with PDO (and I can assure you that OOP is not that scaring. Although it require some knowledge when writing, it is very easy to use a ready made class. The only difference from familiar functions is a little -> thing. Not a big deal)

                  那么,给你:

                  function db_connect_select() 
                  {
                      $dsn = 'mysql:host='.MYSQL_HOSTNAME.';dbname='.DATABASE.';charset=utf8';
                      $opt = array(
                          PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
                          PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
                      ); 
                      return new PDO($dsn,USERNAME_SELECT, PASSWORD, $opt);
                  }
                  
                  function db_result_to_array($query,) 
                  {
                    // not needed with PDO
                  }
                  
                  function select_top_tags()
                  {
                      global $pdo;
                  
                      $query = 'SELECT * FROM top_tags ORDER BY tag_name ASC';
                      $stm = $pdo->prepare($query);
                      $stm->execute();
                      return $stm->fetchAll();
                  }
                  

                  用法:

                  $pdo = db_connect_select(); // somewhere in a bootstrap file
                  $tags = select_top_tags();
                  

                  这篇关于弃用的 MySql 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                • <i id='EYy0G'><tr id='EYy0G'><dt id='EYy0G'><q id='EYy0G'><span id='EYy0G'><b id='EYy0G'><form id='EYy0G'><ins id='EYy0G'></ins><ul id='EYy0G'></ul><sub id='EYy0G'></sub></form><legend id='EYy0G'></legend><bdo id='EYy0G'><pre id='EYy0G'><center id='EYy0G'></center></pre></bdo></b><th id='EYy0G'></th></span></q></dt></tr></i><div id='EYy0G'><tfoot id='EYy0G'></tfoot><dl id='EYy0G'><fieldset id='EYy0G'></fieldset></dl></div>
                  <legend id='EYy0G'><style id='EYy0G'><dir id='EYy0G'><q id='EYy0G'></q></dir></style></legend>
                • <small id='EYy0G'></small><noframes id='EYy0G'>

                      <tfoot id='EYy0G'></tfoot>
                        <bdo id='EYy0G'></bdo><ul id='EYy0G'></ul>

                            <tbody id='EYy0G'></tbody>