pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

        <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="ln7v7zh" id='Indzi'><tfoot id='Indzi'></tfoot><dl id='Indzi'><fieldset id='Indzi'></fieldset></dl></div>

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

        如何將使用 mysql_ 函數(shù)的腳本轉(zhuǎn)換為使用 mysqli_

        How do I convert a script using mysql_ functions to use mysqli_ functions?(如何將使用 mysql_ 函數(shù)的腳本轉(zhuǎn)換為使用 mysqli_ 函數(shù)?)
      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="1jfh7f7" 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_ 函數(shù)的腳本轉(zhuǎn)換為使用 mysqli_ 函數(shù)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

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

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

                  需要采取哪些步驟才能將腳本從使用已棄用的mysql_ 函數(shù)轉(zhuǎn)換為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_ 函數(shù)的基本腳本:

                  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_ 轉(zhuǎn)換為 mysqli_ 可能不是最佳的.如果您準備將所有代碼轉(zhuǎn)換為 面向?qū)ο?

                  嘗試用 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 你可以換掉它們的函數(shù)名.

                  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);
                  

                  選擇數(shù)據(jù)庫

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

                  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.

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

                  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);
                  

                  作為獎勵,您還可以將數(shù)據(jù)庫名稱作為第四個參數(shù)傳遞給 mysqli_connect - 繞過調(diào)用 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 非常相似.您只需要將連接對象作為第一個參數(shù)傳遞.

                  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_ 函數(shù)開始被棄用的一個原因是它們無法處理準備好的語句.如果您只是將代碼轉(zhuǎn)換為 mysqli_ 而沒有采取這一重要步驟,那么您將受到 mysql_ 函數(shù)的一些最大弱點的影響.

                  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.

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

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

                  維基百科 - 準備好的聲明

                  PHP.net - MySQLi 準備好的語句

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

                  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 需要連接對象作為其第一個參數(shù).但是如果連接失敗怎么辦?mysqli_ 引入了一小組不需要連接對象的函數(shù):mysqli_connect_* 函數(shù).

                  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);
                      }
                  }
                  

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

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

                  相關(guān)文檔推薦

                  store_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
                  Call to undefined function mysqli_result::num_rows()(調(diào)用未定義的函數(shù) mysqli_result::num_rows())
                  PHP Prepared Statement Problems(PHP 準備好的語句問題)
                  mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一個結(jié)果)
                  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="rdrdpvp" 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>

                            主站蜘蛛池模板: 安平县鑫川金属丝网制品有限公司,声屏障,高速声屏障,百叶孔声屏障,大弧形声屏障,凹凸穿孔声屏障,铁路声屏障,顶部弧形声屏障,玻璃钢吸音板 | 深圳高新投三江工业消防解决方案提供厂家_服务商_园区智慧消防_储能消防解决方案服务商_高新投三江 | IPO咨询公司-IPO上市服务-细分市场研究-龙马咨询| 派克防爆伺服电机品牌|国产防爆伺服电机|高低温伺服电机|杭州摩森机电科技有限公司 | 合肥风管加工厂-安徽螺旋/不锈钢风管-通风管道加工厂家-安徽风之范 | PCB厂|线路板厂|深圳线路板厂|软硬结合板厂|电路板生产厂家|线路板|深圳电路板厂家|铝基板厂家|深联电路-专业生产PCB研发制造 | 安徽合肥格力空调专卖店_格力中央空调_格力空调总经销公司代理-皖格制冷设备 | 卫浴散热器,卫浴暖气片,卫生间背篓暖气片,华圣格浴室暖气片 | 设定时间记录电子秤-自动累计储存电子秤-昆山巨天仪器设备有限公司 | 生鲜配送系统-蔬菜食材配送管理系统-连锁餐饮订货配送软件-挪挪生鲜供应链管理软件 | 山东艾德实业有限公司| 南昌旅行社_南昌国际旅行社_南昌国旅在线 | 自动化展_机器人展_机床展_工业互联网展_广东佛山工博会 | 沟盖板_复合沟盖板厂_电力盖板_树脂雨水篦子-淄博拜斯特 | 桁架楼承板-钢筋桁架楼承板-江苏众力达钢筋楼承板厂 | 智能家居全屋智能系统多少钱一套-小米全套价格、装修方案 | 深圳市索富通实业有限公司-可燃气体报警器 | 可燃气体探测器 | 气体检测仪 | 高柔性拖链电缆_卷筒电缆_耐磨耐折聚氨酯电缆-玖泰特种电缆 | 科普仪器菏泽市教育教学仪器总厂 | led冷热冲击试验箱_LED高低温冲击试验箱_老化试验箱-爱佩百科 | 电动卫生级调节阀,电动防爆球阀,电动软密封蝶阀,气动高压球阀,气动对夹蝶阀,气动V型调节球阀-上海川沪阀门有限公司 | 电缆接头_防水接头_电缆防水接头_防水电缆接头_上海闵彬 | 拖鞋定制厂家-品牌拖鞋代加工厂-振扬实业中国高端拖鞋大型制造商 | 广州展览制作工厂—[优简]直营展台制作工厂_展会搭建资质齐全 | 杭州代理记账多少钱-注册公司代办-公司注销流程及费用-杭州福道财务管理咨询有限公司 | 无尘烘箱_洁净烤箱_真空无氧烤箱_半导体烤箱_电子防潮柜-深圳市怡和兴机电 | 湖南印刷厂|长沙印刷公司|画册印刷|挂历印刷|台历印刷|杂志印刷-乐成印刷 | SRRC认证_电磁兼容_EMC测试整改_FCC认证_SDOC认证-深圳市环测威检测技术有限公司 | 手表腕表维修保养鉴定售后服务中心网点 - 名表维修保养 | 柔性输送线|柔性链板|齿形链-上海赫勒输送设备有限公司首页[输送机] | 广州迈驰新GMP兽药包装机首页_药品包装机_中药散剂包装机 | 拖链电缆_柔性电缆_伺服电缆_坦克链电缆-深圳市顺电工业电缆有限公司 | 幂简集成 - 品种超全的API接口平台, 一站搜索、试用、集成国内外API接口 | 仓储货架_南京货架_钢制托盘_仓储笼_隔离网_环球零件盒_诺力液压车_货架-南京一品仓储设备制造公司 | 斗式提升机,斗式提升机厂家-淄博宏建机械有限公司 | 螺旋压榨机-刮泥机-潜水搅拌机-电动泥斗-潜水推流器-南京格林兰环保设备有限公司 | 船用烟火信号弹-CCS防汛救生圈-船用救生抛绳器(海威救生设备) | 自动气象站_农业气象站_超声波气象站_防爆气象站-山东万象环境科技有限公司 | 重庆私家花园设计-别墅花园-庭院-景观设计-重庆彩木园林建设有限公司 | 烟台金蝶财务软件,烟台网站建设,烟台网络推广 | 千斤顶,液压千斤顶-力良企业,专业的液压千斤顶制造商,shliliang.com |