久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

        <bdo id='Indzi'></bdo><ul id='Indzi'></ul>

      <legend id='Indzi'><style id='Indzi'><dir id='Indzi'><q id='Indzi'></q></dir></style></legend>

      1. <tfoot id='Indzi'></tfoot>
      2. <i id='Indzi'><tr id='Indzi'><dt id='Indzi'><q id='Indzi'><span id='Indzi'><b id='Indzi'><form id='Indzi'><ins id='Indzi'></ins><ul id='Indzi'></ul><sub id='Indzi'></sub></form><legend id='Indzi'></legend><bdo id='Indzi'><pre id='Indzi'><center id='Indzi'></center></pre></bdo></b><th id='Indzi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Indzi'><tfoot id='Indzi'></tfoot><dl id='Indzi'><fieldset id='Indzi'></fieldset></dl></div>

        <small id='Indzi'></small><noframes id='Indzi'>

        如何將使用 mysql_ 函數的腳本轉換為使用 mysqli_

        How do I convert a script using mysql_ functions to use mysqli_ functions?(如何將使用 mysql_ 函數的腳本轉換為使用 mysqli_ 函數?)
      3. <tfoot id='rXf49'></tfoot>

        <i id='rXf49'><tr id='rXf49'><dt id='rXf49'><q id='rXf49'><span id='rXf49'><b id='rXf49'><form id='rXf49'><ins id='rXf49'></ins><ul id='rXf49'></ul><sub id='rXf49'></sub></form><legend id='rXf49'></legend><bdo id='rXf49'><pre id='rXf49'><center id='rXf49'></center></pre></bdo></b><th id='rXf49'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rXf49'><tfoot id='rXf49'></tfoot><dl id='rXf49'><fieldset id='rXf49'></fieldset></dl></div>

            1. <small id='rXf49'></small><noframes id='rXf49'>

                <tbody id='rXf49'></tbody>
                <bdo id='rXf49'></bdo><ul id='rXf49'></ul>
              • <legend id='rXf49'><style id='rXf49'><dir id='rXf49'><q id='rXf49'></q></dir></style></legend>

                • 本文介紹了如何將使用 mysql_ 函數的腳本轉換為使用 mysqli_ 函數?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  是否使用 mysqli_ 超出了這個問題的范圍.考慮使用 PDO.

                  Whether or not to use mysqli_ is outside the scope of this question. Consider using PDO.

                  需要采取哪些步驟才能將腳本從使用已棄用的mysql_ 函數轉換為mysqli_?

                  What steps need to be taken to convert a script from using the deprecated mysql_ functions to mysqli_?

                  在使用 mysqli_ 而不是 mysql 時,有什么需要做的不同嗎?

                  Is there anything that needs to be done differently when using mysqli_ instead of mysql?

                  這是一個使用 mysql_ 函數的基本腳本:

                  Here's a basic script using mysql_ functions:

                  <?php
                  
                  //define host, username and password
                  
                  $con = mysql_connect($host,$username,$password);
                  if (!$con) {
                      die('Could not connect: ' . mysql_error());
                  }
                  
                  $db_name ="db1";
                  mysql_select_db($dbname, $con);
                  
                  $value1 = mysql_real_escape_string($input_string);
                  
                  $query = 'SELECT * FROM table1 WHERE table1.col1=' . $value1 . '';
                  $result = mysql_query($query, $con);
                  
                  while($row = mysql_fetch_assoc*$result)
                  {
                      $col1 = $row['col1'];
                      $col2 = $row['col2'];
                  
                      echo $col1 . ' ' . $col2 . '<br />';
                  }
                  
                  mysql_close($con);
                  ?>
                  

                  推薦答案

                  注意:mysql_ 轉換為 mysqli_ 可能不是最佳的.如果您準備將所有代碼轉換為 面向對象.

                  嘗試用 mysqli_ 替換 mysql_ 的所有實例并祈禱它起作用是很誘人的.你會很接近但不完全正確.

                  Note: Converting from mysql_ to mysqli_ may not be optimal. Consider PDO if you're prepared to convert all of your code to OOP.

                  It can be tempting to try to replace all instances of mysql_ with mysqli_ and pray it works. You'd be close but not quite on point.

                  幸運的是,mysqli_connect 的工作非常接近mysql_query 你可以換掉它們的函數名.

                  Fortunately, mysqli_connect works closely enough to mysql_query that you can just swap out their function names.

                  mysql_:

                  $con = mysql_connect($host, $username, $password);
                  

                  mysqli_:

                  $con = mysqli_connect($host, $username, $password);
                  

                  選擇數據庫

                  現在,對于mysqli_ 庫中的大多數其他函數,您需要將mysqli_select_db 數據庫連接作為其第一范圍.大多數mysqli_ 函數首先需要連接對象.

                  Selecting a database

                  Now, with most of the other functions in the mysqli_ library, you'll need to pass mysqli_select_db the database connection as its first parameter. Most of the mysqli_ functions require the connection object first.

                  對于這個函數,你可以切換傳遞給函數的參數的順序.如果您之前沒有向它傳遞連接對象,現在必須將其添加為第一個參數.

                  For this function, you can just switch the order of the arguments you pass to the function. If you didn't pass it a connection object before, you have to add it as the first parameter now.

                  mysql_:

                  mysql_select_db($dbname, $con);
                  

                  mysqli_:

                  mysqli_select_db($con, $dbname);
                  

                  作為獎勵,您還可以將數據庫名稱作為第四個參數傳遞給 mysqli_connect - 繞過調用 mysqli_select_db 的需要.

                  As a bonus, you can also pass the database name as the fourth parameter to mysqli_connect - bypassing the need to call mysqli_select_db.

                  $con = mysqli_connect($host, $username, $password, $dbname);
                  

                  清理用戶輸入

                  使用mysqli_real_escape_stringmysql_real_escape_string 非常相似.您只需要將連接對象作為第一個參數傳遞.

                  Sanitize user input

                  Using mysqli_real_escape_string is very similar to mysql_real_escape_string. You just need to pass the connection object as the first parameter.

                  mysql_:

                  $value1 = mysql_real_escape_string($input_string);
                  

                  mysqli_:

                  $value1 = mysqli_real_escape_string($con, $input_string);
                  

                  非常重要:準備和運行查詢

                  mysql_ 函數開始被棄用的一個原因是它們無法處理準備好的語句.如果您只是將代碼轉換為 mysqli_ 而沒有采取這一重要步驟,那么您將受到 mysql_ 函數的一些最大弱點的影響.

                  Very Important: Preparing and Running a Query

                  One reason the mysql_ functions were deprecated to begin with was their inability to handle prepared statements. If you simply convert your code to mysqli_ without taking this important step, you are subject to some of the largest weaknesses of the mysql_ functions.

                  值得閱讀這些關于準備好的語句及其好處的文章:

                  It's worth reading these articles on prepared statements and their benefits:

                  維基百科 - 準備好的聲明

                  PHP.net - MySQLi 準備好的語句

                  注意:使用準備好的語句時,最好明確列出您嘗試查詢的每一列,而不是使用 * 符號來查詢所有列.通過這種方式,您可以確保在對 mysqli_stmt_bind_result 的調用中考慮了所有列.

                  Note: When using prepared statements, it's best to explicitly list each column you're attempting to query, rather than using the * notation to query all columns. This way you can ensure you've accounted for all of the columns in your call to mysqli_stmt_bind_result.

                  mysql_:

                  $query = 'SELECT * FROM table1 WHERE table1.col1=' . $value1 . '';
                  $result = mysql_query($query, $con);
                  while($row = mysql_fetch_assoc*$result)
                  {
                      $col1 = $row['col1'];
                      $col2 = $row['col2'];
                  
                      echo $col1 . ' ' . $col2 . '<br />';
                  }
                  

                  mysqli_:

                  $query = 'SELECT col1,col2 FROM table1 WHERE table1.col1=?';
                  if ($stmt = mysqli_prepare($link, $query)) {
                  
                      /* pass parameters to query */
                      mysqli_stmt_bind_param($stmt, "s", $value1);
                  
                      /* run the query on the database */
                      mysqli_stmt_execute($stmt);
                  
                      /* assign variable for each column to store results in */
                      mysqli_stmt_bind_result($stmt, $col1, $col2);
                  
                      /* fetch values */
                      while (mysqli_stmt_fetch($stmt)) {
                          /*
                              on each fetch, the values for each column 
                              in the results are automatically stored in 
                              the variables we assigned using 
                              "mysqli_stmt_bind_result"
                          */
                          echo $col1 . ' ' . $col2 . '<br />';
                      }
                  
                      /* close statement */
                      mysqli_stmt_close($stmt);
                  }
                  

                  顯示錯誤

                  顯示錯誤的方式與 mysqli_ 略有不同.mysqli_error 需要連接對象作為其第一個參數.但是如果連接失敗怎么辦?mysqli_ 引入了一小組不需要連接對象的函數:mysqli_connect_* 函數.

                  Showing errors

                  Showing errors works a little differently with mysqli_. mysqli_error requires the connection object as its first parameter. But what if the connection failed? mysqli_ introduces a small set of functions that don't require the connection object: the mysqli_connect_* functions.

                  mysql_:

                  if (!$con) {
                      die('Could not connect: ' . mysql_error());
                  }
                  
                  if (!$result) {
                      die('SQL Error: ' . mysql_error());
                  }
                  

                  mysqli_:

                  /* check connection error*/
                  if (mysqli_connect_errno()) {
                      die( 'Could not connect: ' . mysqli_connect_error() );
                  }
                  
                  /* check query error */
                  if ($stmt = mysqli_prepare($link, $query)) {
                  
                      // ... execute query
                  
                      if (mysqli_stmt_error($stmt)) {
                          echo 'SQL Error: ' . mysqli_stmt_error($stmt);
                      }
                  }
                  

                  這篇關于如何將使用 mysql_ 函數的腳本轉換為使用 mysqli_ 函數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  store_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
                  Call to undefined function mysqli_result::num_rows()(調用未定義的函數 mysqli_result::num_rows())
                  PHP Prepared Statement Problems(PHP 準備好的語句問題)
                  mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一個結果)
                  PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
                  How do I make sure that values from MySQL keep their type in PHP?(如何確保 MySQL 中的值在 PHP 中保持其類型?)
                  <legend id='9eiLs'><style id='9eiLs'><dir id='9eiLs'><q id='9eiLs'></q></dir></style></legend>
                • <i id='9eiLs'><tr id='9eiLs'><dt id='9eiLs'><q id='9eiLs'><span id='9eiLs'><b id='9eiLs'><form id='9eiLs'><ins id='9eiLs'></ins><ul id='9eiLs'></ul><sub id='9eiLs'></sub></form><legend id='9eiLs'></legend><bdo id='9eiLs'><pre id='9eiLs'><center id='9eiLs'></center></pre></bdo></b><th id='9eiLs'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='9eiLs'><tfoot id='9eiLs'></tfoot><dl id='9eiLs'><fieldset id='9eiLs'></fieldset></dl></div>
                  • <bdo id='9eiLs'></bdo><ul id='9eiLs'></ul>

                    • <small id='9eiLs'></small><noframes id='9eiLs'>

                      <tfoot id='9eiLs'></tfoot>
                          <tbody id='9eiLs'></tbody>

                            主站蜘蛛池模板: 99久久婷婷国产亚洲终合精品 | 亚洲三级国产 | 国产亚洲精品精品国产亚洲综合 | 国产精品一区二区无线 | 在线观看a视频 | 国产精品成人一区二区三区夜夜夜 | 最新国产精品视频 | 欧美乱人伦视频 | 国产美女一区二区三区 | 色综合欧美 | 午夜视频在线观看一区二区 | 日韩精品一区二区三区免费观看 | 日本精品一区二区 | 中文字幕91av | 中文字幕av在线 | 日本中文字幕在线观看 | 久久久人成影片一区二区三区 | 久久精彩| 草久网| 91久久久久久久久久久久久 | 色综合久久天天综合网 | 欧美电影网 | 在线视频日韩 | 亚洲欧美高清 | 欧美在线播放一区 | av黄色在线观看 | 中文字幕视频在线观看 | 欧美精品一级 | 欧美日韩大片 | 日本色高清 | 国产一区在线免费观看 | 国产高清免费视频 | 精品国产一区二区三区四区在线 | 色婷婷综合久久久中字幕精品久久 | 日日躁狠狠躁aaaaxxxx | 色www精品视频在线观看 | 亚洲欧美中文日韩在线v日本 | 久久99精品视频 | 毛片在线看片 | 久久这里只有精品首页 | 一区二区三区视频免费观看 |