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

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

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

    2. <small id='Pljyy'></small><noframes id='Pljyy'>

    3. 無法將內爆數組綁定到 mysql 準備好的語句中

      Trouble binding an imploded array into a mysql prepared statement(無法將內爆數組綁定到 mysql 準備好的語句中)

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

          <tbody id='wMKja'></tbody>

          • <tfoot id='wMKja'></tfoot>

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

              2. 本文介紹了無法將內爆數組綁定到 mysql 準備好的語句中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我對以下語法錯誤感到頭疼.我正在嘗試將內爆數組綁定到準備好的語句中,但出現以下語法錯誤:

                I am beating my head over the below syntax error. I am trying to bind an imploded array into a prepared statement, but I am getting the following syntax error:

                您的 SQL 語法有錯誤;檢查與您的 MySQL 服務器版本相對應的手冊,了解在?"附近使用的正確語法.在第 1 行

                這是我的代碼.誰能看出我哪里出錯了?

                Here is my code. Can anyone see where I am going wrong?

                <?php 
                include('config.php');
                
                $selected = $_POST['selected'];
                
                if ($stmt = $mysqli->prepare("DELETE FROM email_addresses WHERE email_addresses IN ?")) {
                
                    $stmt->bind_param("s", "('" . implode("', '", $selected) . "')" );
                
                    $stmt->execute();
                
                    $stmt->close();
                
                    print "ok";
                
                } else {
                    print $mysqli->error;
                }
                
                $mysqli->close();
                
                ?>
                

                作為測試,我嘗試了:

                print "('" . implode("', '", $selected) . "')";
                

                哪個正確地給了我

                ('me@me.com', 'you@you.com')
                

                推薦答案

                讓我為您省去一些麻煩并告訴您您嘗試做的事情無論如何都行不通.您只將一個參數綁定到您的 IN() 函數調用.您認為您正在傳遞一個逗號分隔的列表,但實際上您只傳遞了一個逗號分隔的字符串,該字符串被視為一個值.這意味著您將搜索具有'me@me.com'、'you@you.com'"值的一條記錄,而不是與me@me.com"匹配的記錄或you@you.com".

                Let me save you some trouble and tell you what you're trying to do won't work anyway. You are only binding one parameter to your IN() function call. You think you're passing a comma separated list but you are actually only passing a comma separated string which is treated as one value. This means you will be search for one record with a value of "'me@me.com', 'you@you.com'" instead of records that match "me@me.com" or "you@you.com".

                要克服這個問題,您需要:

                To overcome this you need to:

                1. 動態生成類型字符串
                2. 使用call_user_func_array()綁定你的參數

                您可以像這樣生成類型字符串:

                You can generate the types string like this:

                $types = str_repeat('s', count($selected));
                

                所有這些都是創建一個 s 的字符串,它的字符數與數組中的元素數一樣多.

                All this does is create a string of s's that is as many characters as the number of elements in the array.

                然后你可以像這樣使用 call_user_func_array() 綁定你的參數(注意我把括號放回 IN() 函數):

                You would then bind your parameters using call_user_func_array() like this (notice I put the parenthesis back in for the IN() function):

                if ($stmt = $mysqli->prepare("DELETE FROM email_addresses WHERE email_addresses IN (?)")) {
                    call_user_func_array(array($stmt, "bind_param"), array_merge($types, $selected));
                

                但是如果你嘗試這個你會得到一個關于 mysqli_stmt::bind_param() 期望參數二通過引用傳遞的錯誤:

                But if you try this you will get an error about mysqli_stmt::bind_param() expecting parameter two to be passed by reference:

                警告:mysqli_stmt::bind_param() 的參數 2 應為引用,已給定值

                Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given

                這有點煩人,但很容易解決.要解決此問題,您可以使用以下函數:

                This is kind of annoying but easy enough to work around. To work around that you can use the following function:

                function refValues($arr){ 
                    $refs = array(); 
                    foreach($arr as $key => $value) 
                        $refs[$key] = &$arr[$key]; 
                    return $refs; 
                } 
                

                它只是創建一個值數組,這些值是對 $selected 數組中值的引用.這足以讓 mysqli_stmt::bind_param() 開心:

                It just creates an array of values that are references to the values in the $selected array. This is enough to make mysqli_stmt::bind_param() happy:

                if ($stmt = $mysqli->prepare("DELETE FROM email_addresses WHERE email_addresses IN (?)")) {
                    call_user_func_array(array($stmt, "bind_param"), array_merge($types, refValues($selected)));
                

                編輯

                從 PHP 5.6 開始,您現在可以使用 ... 運算符來使這更簡單:

                As of PHP 5.6 you can now use the ... operator to make this even simpler:

                $stmt->bind_param($types, ...$selected);
                

                這篇關于無法將內爆數組綁定到 mysql 準備好的語句中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 中保持其類型?)
                <i id='zrQro'><tr id='zrQro'><dt id='zrQro'><q id='zrQro'><span id='zrQro'><b id='zrQro'><form id='zrQro'><ins id='zrQro'></ins><ul id='zrQro'></ul><sub id='zrQro'></sub></form><legend id='zrQro'></legend><bdo id='zrQro'><pre id='zrQro'><center id='zrQro'></center></pre></bdo></b><th id='zrQro'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zrQro'><tfoot id='zrQro'></tfoot><dl id='zrQro'><fieldset id='zrQro'></fieldset></dl></div>

                <tfoot id='zrQro'></tfoot>

                      <tbody id='zrQro'></tbody>

                  1. <legend id='zrQro'><style id='zrQro'><dir id='zrQro'><q id='zrQro'></q></dir></style></legend>
                      • <bdo id='zrQro'></bdo><ul id='zrQro'></ul>

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

                        1. 主站蜘蛛池模板: 在线视频一区二区三区 | 激情六月天 | 国产精品成人一区二区三区 | 国产精品美女www | 亚洲人在线观看视频 | 在线2区 | 精品一区av| 久久久精 | 国产一区中文字幕 | 国产探花 | 999热视频 | 欧美在线免费 | 欧美亚洲另类丝袜综合网动图 | 欧美日韩黄 | 精品日韩一区 | 午夜精品视频在线观看 | 国产视频91在线 | 国产偷录视频叫床高潮对白 | 国产精品视频免费 | 美女在线观看国产 | 国产成人jvid在线播放 | 日韩成人中文字幕 | 色吧综合网 | 国产精品一区在线观看 | 天天干精品| 日韩成人精品 | 中文字幕第十页 | 天堂亚洲 | 国产精品国色综合久久 | 操久久久 | 国产一区二区三区在线 | 亚洲一区在线播放 | 精品乱子伦一区二区三区 | 性做久久久久久免费观看欧美 | 成人在线免费视频观看 | 久久网一区二区三区 | 在线观看国产 | 国产小视频在线 | 日韩精品中文字幕一区二区三区 | 亚洲一区综合 | 日韩欧美一级精品久久 |