久久久久久久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. 無(wú)法將內(nèi)爆數(shù)組綁定到 mysql 準(zhǔn)備好的語(yǔ)句中

      Trouble binding an imploded array into a mysql prepared statement(無(wú)法將內(nèi)爆數(shù)組綁定到 mysql 準(zhǔn)備好的語(yǔ)句中)

        <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. 本文介紹了無(wú)法將內(nèi)爆數(shù)組綁定到 mysql 準(zhǔn)備好的語(yǔ)句中的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                我對(duì)以下語(yǔ)法錯(cuò)誤感到頭疼.我正在嘗試將內(nèi)爆數(shù)組綁定到準(zhǔn)備好的語(yǔ)句中,但出現(xiàn)以下語(yǔ)法錯(cuò)誤:

                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 語(yǔ)法有錯(cuò)誤;檢查與您的 MySQL 服務(wù)器版本相對(duì)應(yīng)的手冊(cè),了解在?"附近使用的正確語(yǔ)法.在第 1 行

                這是我的代碼.誰(shuí)能看出我哪里出錯(cuò)了?

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

                作為測(cè)試,我嘗試了:

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

                哪個(gè)正確地給了我

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

                推薦答案

                讓我為您省去一些麻煩并告訴您您嘗試做的事情無(wú)論如何都行不通.您只將一個(gè)參數(shù)綁定到您的 IN() 函數(shù)調(diào)用.您認(rèn)為您正在傳遞一個(gè)逗號(hào)分隔的列表,但實(shí)際上您只傳遞了一個(gè)逗號(hào)分隔的字符串,該字符串被視為一個(gè)值.這意味著您將搜索具有'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".

                要克服這個(gè)問(wèn)題,您需要:

                To overcome this you need to:

                1. 動(dòng)態(tài)生成類型字符串
                2. 使用call_user_func_array()綁定你的參數(shù)

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

                You can generate the types string like this:

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

                所有這些都是創(chuàng)建一個(gè) s 的字符串,它的字符數(shù)與數(shù)組中的元素?cái)?shù)一樣多.

                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() 綁定你的參數(shù)(注意我把括號(hào)放回 IN() 函數(shù)):

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

                但是如果你嘗試這個(gè)你會(huì)得到一個(gè)關(guān)于 mysqli_stmt::bind_param() 期望參數(shù)二通過(guò)引用傳遞的錯(cuò)誤:

                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() 的參數(shù) 2 應(yīng)為引用,已給定值

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

                這有點(diǎn)煩人,但很容易解決.要解決此問(wèn)題,您可以使用以下函數(shù):

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

                它只是創(chuàng)建一個(gè)值數(shù)組,這些值是對(duì) $selected 數(shù)組中值的引用.這足以讓 mysqli_stmt::bind_param() 開(kāi)心:

                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 開(kāi)始,您現(xiàn)在可以使用 ... 運(yùn)算符來(lái)使這更簡(jiǎn)單:

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

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

                這篇關(guān)于無(wú)法將內(nèi)爆數(shù)組綁定到 mysql 準(zhǔn)備好的語(yǔ)句中的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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 準(zhǔn)備好的語(yǔ)句問(wèn)題)
                mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一個(gè)結(jié)果)
                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. 主站蜘蛛池模板: 美日韩免费 | 91精品国产91久久综合桃花 | 亚洲午夜在线 | 色偷偷人人澡人人爽人人模 | 国产精品久久九九 | 成人深夜福利在线观看 | 精品国产乱码久久久久久图片 | 成人午夜网站 | 国产区久久| 国产高清在线精品 | 国产欧美一区二区三区另类精品 | 日韩电影中文字幕 | 欧美精品一区三区 | 成人在线小视频 | 亚洲一区导航 | 免费亚洲成人 | 视频精品一区 | 日韩欧美在线观看 | 岛国av在线免费观看 | 国产成人免费观看 | 中文字幕在线剧情 | 天天综合亚洲 | 一区二区手机在线 | www97影院 | 夜久久 | 国产伦精品 | 日韩在线精品视频 | 精品久草 | 精品亚洲视频在线 | 五月婷亚洲 | 亚洲欧美中文日韩在线v日本 | 精品成人在线 | 999热精品| 久久亚洲视频 | 一级做a毛片 | 色婷婷综合久久久久中文一区二区 | 久久男人天堂 | 成人性生交a做片 | 黄色片在线免费看 | 久草新在线 | 国产精品波多野结衣 |