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

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

      • <bdo id='tV8dJ'></bdo><ul id='tV8dJ'></ul>

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

      <tfoot id='tV8dJ'></tfoot>
    1. PDO 返回不正确但重复的数据.密钥不在数据库中

      时间:2023-09-19

      1. <i id='5aIAd'><tr id='5aIAd'><dt id='5aIAd'><q id='5aIAd'><span id='5aIAd'><b id='5aIAd'><form id='5aIAd'><ins id='5aIAd'></ins><ul id='5aIAd'></ul><sub id='5aIAd'></sub></form><legend id='5aIAd'></legend><bdo id='5aIAd'><pre id='5aIAd'><center id='5aIAd'></center></pre></bdo></b><th id='5aIAd'></th></span></q></dt></tr></i><div id='5aIAd'><tfoot id='5aIAd'></tfoot><dl id='5aIAd'><fieldset id='5aIAd'></fieldset></dl></div>
          <tbody id='5aIAd'></tbody>
          <bdo id='5aIAd'></bdo><ul id='5aIAd'></ul>

            <legend id='5aIAd'><style id='5aIAd'><dir id='5aIAd'><q id='5aIAd'></q></dir></style></legend>
                <tfoot id='5aIAd'></tfoot>

                <small id='5aIAd'></small><noframes id='5aIAd'>

              1. 本文介绍了PDO 返回不正确但重复的数据.密钥不在数据库中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我刚开始使用 $pdo 语句,所以可能很简单,我还没有在 php.net 上阅读过.我在查询数据库时收到重复的结果.

                I'm new to using $pdo statements so might be something simple I haven't yet read on php.net. I'm receiving duplicate results when querying the database.

                结果:

                [0] => Array
                    (
                        [umeta_id] => 31
                        [0] => 31
                        [user_id] => 2
                        [1] => 2
                        [meta_key] => fbmeta
                        [2] => fbmeta
                        [meta_value] => someMetaValueStuff;
                        [3] => someMetaValueStuff;
                    )
                

                查询很简单:

                function getData(){
                    global $pdo;
                    $query = $pdo->prepare('SELECT * FROM usermeta WHERE meta_key = "fbmeta" LIMIT 0,30');
                    $query->execute();
                
                    return $query->fetchAll();
                }
                
                print_r( getData() );
                

                问题是命名键 (umeta_id, user_id, meta_key, meta_value) 确实存在,数字键没有.查询如何返回这些?我该如何防止它们被退回?

                The problem is that the named keys (umeta_id, user_id, meta_key, meta_value) DO exist, the numeric keys do not. How come the query returns these? And how do I prevent them from even being returned?

                推荐答案

                它不是重复的,它只是您正在使用的当前 FETCH_MODE.要获得关联键,您只需要这样指定;默认情况下,它同时获取.

                It's not duplicates, it's just the current FETCH_MODE you're using. To get as associative keys only you need to specify as such; by default it fetches as both.

                像这样使用:

                $query->fetchAll(PDO::FETCH_NUM); // to fetch with numeric indexes
                $query->fetchAll(PDO::FETCH_ASSOC); // to fetch with associative indexes
                

                fetchAll 文档
                获取文档

                这篇关于PDO 返回不正确但重复的数据.密钥不在数据库中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:插入前检查数据库中是否存在行 下一篇:调用未定义的方法 PDO::execute()

                相关文章

                最新文章

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

                2. <tfoot id='jUC88'></tfoot>
                3. <legend id='jUC88'><style id='jUC88'><dir id='jUC88'><q id='jUC88'></q></dir></style></legend>
                    <bdo id='jUC88'></bdo><ul id='jUC88'></ul>

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