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

<tfoot id='WmON0'></tfoot>

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

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

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

    1. mysqli_prepare 與 PDO

      mysqli_prepare vs PDO(mysqli_prepare 與 PDO)

            <tbody id='BiQg1'></tbody>
            • <small id='BiQg1'></small><noframes id='BiQg1'>

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

                <tfoot id='BiQg1'></tfoot>

                <legend id='BiQg1'><style id='BiQg1'><dir id='BiQg1'><q id='BiQg1'></q></dir></style></legend>
                本文介紹了mysqli_prepare 與 PDO的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                背景

                我正在嘗試編寫函數查詢

                I'm trying to write a function query

                query('type', 'parameters', 'bind_types')
                

                我可以調用它來進行簡單的查詢.所有的mySQL查詢都在函數

                which I can call to make simple queries. All the mySQL queries are in the function

                grab_sql()
                

                所有的綁定都發生在函數bind()

                All the binding takes place in the function bind()

                call_user_func_array 需要引用才能正常運行,所以我寫了 ref_arr 來適應.

                call_user_func_array needs references to function correctly so I wrote ref_arr to accomodate.

                問題是我沒有得到我需要的結果 - 它們發布在結果下方.我認為問題在于結果的綁定,正如我在這部分猜測的那樣.

                Problem is that I'm not getting the results back that I need - they are posted below under results. I think the issue is in the binding of the reuslts as I kind of guessed on that part.

                研究

                • 關于預處理語句的信息此處
                • 有關call_user_func_array 的信息此處
                • 關于call_user_func_array 引用必要性的信息這里
                • Info on prepared statements here
                • Info on call_user_func_array here
                • Info on the neccessity of references for call_user_func_array here

                問題:如何修改此代碼以正確獲得正確的結果?

                QUESTION: How can I modify this code to correctly get the correct results?

                代碼

                  function ref_arr(&$arr)
                    { 
                    $refs = array(); 
                    foreach($arr as $key => $value) 
                      {  
                      $refs[$key] = &$arr[$key];
                      } 
                    return $refs;}      
                
                  public function bind($query, $input_param, $btypes)
                    {   
                    $a="test_var1";$b="test_var2";
                    $output_arr=array($a,$b);
                    $input_ref = $this->ref_arr($input_param);
                    $output_ref = $this->ref_arr($output_arr);
                    if($statement=mysqli_prepare(one::$db, $query)) 
                      {
                      array_unshift($input_ref, $statement, $btypes);
                      call_user_func_array("mysqli_stmt_bind_param", $input_ref);
                      mysqli_stmt_execute($statement);
                      array_unshift($output_ref, $statement);
                      call_user_func_array("mysqli_stmt_bind_result", $output_ref);
                      mysqli_stmt_fetch($statement);
                      var_dump($output_ref);  
                      mysqli_stmt_close($statement);
                      }
                    }
                  public function grab($type)
                    {
                    switch($type) 
                      {
                      case "validate_user":
                        $query="SELECT email,pass FROM cr WHERE email=? AND pass=?";
                        break;
                      case "another_query_type":
                        break;
                      }
                    return $query;
                    }
                  public function query($qtype, $arg_arr, $btypes)
                    {
                    return self::bind(self::grab_sql($qtype), $arg_arr, $btypes);
                    }
                  }
                

                測試用例

                <?php
                  require_once 'p0.php'; 
                  $db_ = new database();
                  $db_->query('validate_user',array('joe@gmail.com','Password'), 'ss');
                ?>
                

                結果

                值結果似乎是(最后兩個值)&NULL 和 &NULL.

                The values result appears to be(last two values) &NULL and &NULL.

                array(3) { [0]=> object(mysqli_stmt)#2 (9) {  
                    ["affected_rows"]=> int(-1) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(2) ["field_count"]=> int(2) ["errno"]=> int(0) ["error"]=> string(0) "" ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) } [1]=> &NULL [2]=> &NULL 
                } 
                

                推薦答案

                是的,在 Mysqli 中編寫通用的 bind-this-array-into-a-query 是一個皇家 PITA.當我編寫 Zend Framework 的 mysqli 適配器時,我最終讓它工作了,但這需要大量的工作.歡迎您查看代碼.我看到了一個主要區別,這是我如何做參考的:

                Yes, writing a generic bind-this-array-into-a-query in Mysqli is a royal PITA. I eventually got it to work when I was coding Zend Framework's mysqli adapter, but it took a lot of work. You're welcome to take a look at the code. I see one chief difference, here's how I did the refs:

                $stmtParams = array();
                foreach ($params as $k => &$value) {
                    $stmtParams[$k] = &$value;
                }
                call_user_func_array(
                    array($this->_stmt, 'bind_param'), // mysqli OO callback
                    $stmtParams
                );
                

                這與您的略有不同.我想知道在您的代碼中,引用運算符 & 是否比數組索引 [] 運算符綁定得更緊密.

                This is slightly different than yours. I wonder if in your code the ref operator & binds more tightly than the array index [] operator.

                注意我還必須在 foreach 和賦值中使用 ref 運算符.我一直不明白為什么,但這是唯一可行的方法.PHP 引用非常神秘且難以理解.

                Note I also had to use the ref operator both in the foreach and in the assignment. I never quite understood why, but this was the only way it would work. PHP refs are pretty mysterious and hard to understand.

                如果您堅持使用啟用了 Mysqli 但未啟用 PDO 的環境,這可能不是一個可行的建議,但您確實應該考慮改用 PDO.PDO 會為您處理很多工作;您可以簡單地將一組值傳遞給 PDOStatement::execute() 用于帶參數的準備好的查詢.對我來說,將 PDO 用于這種特殊用途比使用 mysqli 要容易得多.

                This may not be a viable suggestion if you're stuck with an environment that has Mysqli enabled but not PDO, but you should really consider using PDO instead. PDO takes care of a lot of that work for you; you can simply pass an array of values to PDOStatement::execute() for a prepared query with parameters. For me, it was far easier to use PDO for this particular use than mysqli.

                $pdoStmt->execute( array('joe@gmail.com','Password') );  // it's that easy
                

                PS:我希望你 不是以明文形式存儲密碼.

                這篇關于mysqli_prepare 與 PDO的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 中保持其類型?)
                <tfoot id='uD9V9'></tfoot>

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

                    • <legend id='uD9V9'><style id='uD9V9'><dir id='uD9V9'><q id='uD9V9'></q></dir></style></legend>

                        <tbody id='uD9V9'></tbody>

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

                          主站蜘蛛池模板: 国产成人精品高清久久 | 羞羞的视频网站 | 成人国产精品久久久 | 羞视频在线观看 | 国产免费观看一区 | 精品国产乱码久久久久久闺蜜 | 91在线精品秘密一区二区 | 亚洲精品中文字幕在线观看 | 日本精品一区 | 久草视频在线播放 | 丁香综合 | 国产三级| 国产精品成人一区二区三区夜夜夜 | 一级片在线观看 | 一区二区视频 | 手机av在线 | 亚洲视频区 | 91欧美 | 亚洲成人av一区二区 | 91玖玖| 毛片在线视频 | 欧美一区二区激情三区 | 亚洲精品久久久久久久久久久久久 | 91久久国产综合久久91精品网站 | 在线一区视频 | 日本成人久久 | 欧美一级片在线 | 一区在线视频 | 亚洲高清网 | 日韩欧美在线视频一区 | 日韩av一区二区在线观看 | 国产一区二区久久 | 九九久久在线看 | 日韩在线欧美 | 狠狠干天天干 | 日韩精品一区二区三区 | 亚洲高清在线播放 | 国产丝袜一区二区三区免费视频 | 欧美视频在线播放 | a a毛片| 精品视频 免费 |