• <small id='vJeBi'></small><noframes id='vJeBi'>

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

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

        如何读取“fetch(PDO::FETCH_ASSOC);"

        时间:2023-09-21
            <legend id='FXZlY'><style id='FXZlY'><dir id='FXZlY'><q id='FXZlY'></q></dir></style></legend>
              <tbody id='FXZlY'></tbody>
          • <small id='FXZlY'></small><noframes id='FXZlY'>

            <i id='FXZlY'><tr id='FXZlY'><dt id='FXZlY'><q id='FXZlY'><span id='FXZlY'><b id='FXZlY'><form id='FXZlY'><ins id='FXZlY'></ins><ul id='FXZlY'></ul><sub id='FXZlY'></sub></form><legend id='FXZlY'></legend><bdo id='FXZlY'><pre id='FXZlY'><center id='FXZlY'></center></pre></bdo></b><th id='FXZlY'></th></span></q></dt></tr></i><div id='FXZlY'><tfoot id='FXZlY'></tfoot><dl id='FXZlY'><fieldset id='FXZlY'></fieldset></dl></div>
                  <bdo id='FXZlY'></bdo><ul id='FXZlY'></ul>
                  <tfoot id='FXZlY'></tfoot>
                  本文介绍了如何读取“fetch(PDO::FETCH_ASSOC);"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 PHP 构建 Web 应用程序,并且正在使用 Memcached 进行存储来自数据库的用户数据.

                  I am trying to build a web application using PHP and I am using Memcached for storing user data from the database.

                  例如,假设我有这个代码:

                  For example, let’s say that I have this code:

                   $sql    = "SELECT * FROM users WHERE user_id = :user_id";
                  $stmt   = $this->_db->prepare($sql);
                  $result = $stmt->execute(array(":user_id" => $user_id));
                  $user   = $stmt->fetch(PDO::FETCH_ASSOC);
                  

                  我不太确定如何读取 $user 变量并从中获取数据.我需要能够阅读电子邮件和密码栏.

                  I am not really sure how to read the $user variable and get the data out of it. I will need to be able to read the email and password column.

                  这是如何工作的?

                  推荐答案

                  PDOStatement::fetch 从结果集中返回一行.参数 PDO::FETCH_ASSOC 告诉 PDO 将结果作为关联数组返回.

                  PDOStatement::fetch returns a row from the result set. The parameter PDO::FETCH_ASSOC tells PDO to return the result as an associative array.

                  数组键将匹配您的列名.如果您的表包含列 'email' 和 'password',则数组的结构如下:

                  The array keys will match your column names. If your table contains columns 'email' and 'password', the array will be structured like:

                  Array
                  (
                      [email] => 'youremail@yourhost.com'
                      [password] => 'yourpassword'
                  )
                  

                  要从电子邮件"列中读取数据,请执行以下操作:

                  To read data from the 'email' column, do:

                  $user['email'];
                  

                  和密码":

                  $user['password'];
                  

                  这篇关于如何读取“fetch(PDO::FETCH_ASSOC);"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PDO/PHP - 检查行是否存在 下一篇:参数化 PDO 查询和 `LIMIT` 子句 - 不工作

                  相关文章

                  最新文章

                    <bdo id='V5qW8'></bdo><ul id='V5qW8'></ul>
                • <small id='V5qW8'></small><noframes id='V5qW8'>

                • <tfoot id='V5qW8'></tfoot>
                • <legend id='V5qW8'><style id='V5qW8'><dir id='V5qW8'><q id='V5qW8'></q></dir></style></legend>

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