<bdo id='HP1l0'></bdo><ul id='HP1l0'></ul>
    <tfoot id='HP1l0'></tfoot>

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

  1. <i id='HP1l0'><tr id='HP1l0'><dt id='HP1l0'><q id='HP1l0'><span id='HP1l0'><b id='HP1l0'><form id='HP1l0'><ins id='HP1l0'></ins><ul id='HP1l0'></ul><sub id='HP1l0'></sub></form><legend id='HP1l0'></legend><bdo id='HP1l0'><pre id='HP1l0'><center id='HP1l0'></center></pre></bdo></b><th id='HP1l0'></th></span></q></dt></tr></i><div id='HP1l0'><tfoot id='HP1l0'></tfoot><dl id='HP1l0'><fieldset id='HP1l0'></fieldset></dl></div>
    <legend id='HP1l0'><style id='HP1l0'><dir id='HP1l0'><q id='HP1l0'></q></dir></style></legend>
    1. PDO fetch 只返回第一行

      时间:2023-10-05

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

              <tbody id='NBjog'></tbody>
              <legend id='NBjog'><style id='NBjog'><dir id='NBjog'><q id='NBjog'></q></dir></style></legend>

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

                本文介绍了PDO fetch 只返回第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我使用以下代码连接数据库,获取Data_length索引列,并根据数据计算数据库大小.

                I'm using the following code to make a connection to the database, fetch the Data_length index column, and calculate the database size based on the data.

                出于某种原因,PDO 将始终返回0",这是第一行中 Data_length 索引的值.无论我做什么,我都只得到第一行索引.

                For some reason PDO will always return "0", which is the value for the Data_length index in the first row. Whatever I do, I only get the first rows index.

                数据库为 MySQL,引擎为 MyISAM.

                The database is MySQL, the engine MyISAM.

                PHP 版本:5.5.38
                MySQL 版本:5.5.50

                PHP Version: 5.5.38
                MySQL Version: 5.5.50

                这是源代码.

                <!DOCTYPE html>
                <head>
                <title></title>
                </head>
                <body>
                
                <?php
                try {
                    error_reporting(-1);
                    $host_name  = "my_host";
                    $database   = "my_db";
                    $user_name  = "my_user";
                    $password   = "my_pwd";
                    $conn = new PDO("mysql:host=$host_name;dbname=$database", $user_name, $password);
                    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                
                    $sth = $conn->query('SHOW TABLE STATUS');
                    $dbSize = 0;
                    $row = $sth->fetch(PDO::FETCH_ASSOC);
                    $dbSize = $row["Data_length"];
                    $decimals = 2;  
                    $mbytes = round($dbSize/(1024*1024),$decimals);
                    echo $dbSize . "
                " . $row["Data_length"];
                    } catch (PDOException $e) {
                    echo 'Connection failed: ' . $e->getMessage();
                }
                ?>
                </body>
                </html>
                

                推荐答案

                添加一个 while 循环,

                Add a while loop,

                while($row= $sth->fetch( PDO::FETCH_ASSOC )){ 
                   echo $row['your_field_name'];
                }
                

                或者你可以使用 fetchAll

                $rows = $sth->fetchAll();
                print_r($rows);
                

                这篇关于PDO fetch 只返回第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用 php pdo 删除我的数据库中的行 下一篇:为什么在连接失败时 PDO 会打印我的密码?

                相关文章

                最新文章

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

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