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

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

        是否可以将 store_result() 和 bind_result() 与 PHP PDO 一

        时间:2023-07-30

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

        <legend id='8uFPV'><style id='8uFPV'><dir id='8uFPV'><q id='8uFPV'></q></dir></style></legend>
        • <small id='8uFPV'></small><noframes id='8uFPV'>

            <tbody id='8uFPV'></tbody>

              • <bdo id='8uFPV'></bdo><ul id='8uFPV'></ul>
              • <tfoot id='8uFPV'></tfoot>

                  本文介绍了是否可以将 store_result() 和 bind_result() 与 PHP PDO 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的问题相当简单:是否可以将 store_result()bind_result() 与 PHP PDO 一起使用?

                  My question is fairly straightforward: Is it possible to use store_result() and bind_result() with PHP PDO?

                  这是我遇到的一些示例代码:

                  Here is some example code I came across:

                  $stmt = $mysqli->prepare("SELECT id, username, password, salt FROM members WHERE email = ? LIMIT 1")) { 
                    $stmt->bind_param('s', $email); // Bind "$email" to parameter.
                    $stmt->execute(); // Execute the prepared query.
                    $stmt->store_result();
                    $stmt->bind_result($user_id, $username, $db_password, $salt); // get variables from result.
                    $stmt->fetch();
                  

                  我已经看到这些在 mysqli 的上下文中使用,但没有在 PHP PDO 中使用.store_result()bind_result() 在 www.php.net 上的 mysqli 中被引用.我很好奇它们是否有效,或者是否有类似的方法.

                  I have seen these used in the context of mysqli, but not with PHP PDO. store_result() and bind_result() are referenced in mysqli on www.php.net. I'm curious if they are valid, or if there are comparable methods.

                  显然这两种方法之间有一些转换.我的假设是 store_resultbind_result() 类似于 PDO 的 fetch() 命令.

                  Obviously there is some translation between the two methods. My assumption is that store_result and bind_result() are similar to PDO's fetch() commands.

                  推荐答案

                  重点是,在 PDO 中既不使用 store_result() 也不使用 bind_result() 绝对没有意义.
                  只需获取您的数据并在您希望的任何地方使用它.这就是 PDO 的意义所在.

                  The point is, there is absolutely no point in using neither store_result() nor bind_result() with PDO.
                  Just get your data and use it anywhere you wish. That's the very point of PDO.

                  $sql  = "SELECT id, username, password, salt FROM members WHERE email = ? LIMIT 1";
                  $stmt = $pdo->prepare($sql);
                  $stmt->execute(array($email));
                  $row  = $stmt->fetch();
                  

                  现在您的用户数据位于 $row 数组中.

                  Now you have your userdata in $row array.

                  将结果行存储在单独的变量中现在很少实践.但是如果你更喜欢这种古老的数据处理方式,你可以添加

                  Storing resulting row in separate variables is very seldom practice nowadays. But if you prefer such ancient way of dealing with data, you could add

                  extract($row);
                  

                  到上面的代码来获取你的全局变量.

                  to the above code to get your global variables.

                  mysqli-way 的主要问题是它极难以任何抽象级别使用.

                  The main problem with mysqli-way is that it is extremely hard to use it with whatever level of abstraction.

                  在现实生活中,我们从不全局范围中调用数据库,而是在这样的函数中调用

                  In the real life we never call for database in the global scope, but rather in a function like this

                  function getUserData() {
                      // getting data
                      return $array;
                  }
                  

                  出于某种原因,这个简单但经常使用的代码在 mysqli 中变得非常困难!在现实生活中,我们不需要单独的变量,而是需要返回单个数组.但是对于mysqli,我们需要先获取这些变量,然后将它们放入数组中,然后才返回它们.简直疯了!

                  and for some reason this simple yet mostly used code become extremely difficult with mysqli! In the real life we don't need separate variables but rather single array to be returned. But with mysqli we need to get these variables first, then put them in array and only then return them. Just crazy!

                  这篇关于是否可以将 store_result() 和 bind_result() 与 PHP PDO 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何解决 PHP 中的“无法通过引用传递参数" 下一篇:PHP mysqli准备语句不起作用

                  相关文章

                  最新文章

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

                      <tfoot id='GZbYH'></tfoot>
                      <legend id='GZbYH'><style id='GZbYH'><dir id='GZbYH'><q id='GZbYH'></q></dir></style></legend>
                    1. <small id='GZbYH'></small><noframes id='GZbYH'>

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