<tfoot id='xWx5j'></tfoot>
  • <small id='xWx5j'></small><noframes id='xWx5j'>

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

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

        Php mysql pdo 查询:用查询结果填充变量

        时间:2023-09-25

        <tfoot id='xGv0E'></tfoot>
        <legend id='xGv0E'><style id='xGv0E'><dir id='xGv0E'><q id='xGv0E'></q></dir></style></legend>

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

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

                <tbody id='xGv0E'></tbody>

              <i id='xGv0E'><tr id='xGv0E'><dt id='xGv0E'><q id='xGv0E'><span id='xGv0E'><b id='xGv0E'><form id='xGv0E'><ins id='xGv0E'></ins><ul id='xGv0E'></ul><sub id='xGv0E'></sub></form><legend id='xGv0E'></legend><bdo id='xGv0E'><pre id='xGv0E'><center id='xGv0E'></center></pre></bdo></b><th id='xGv0E'></th></span></q></dt></tr></i><div id='xGv0E'><tfoot id='xGv0E'></tfoot><dl id='xGv0E'><fieldset id='xGv0E'></fieldset></dl></div>
                1. 本文介绍了Php mysql pdo 查询:用查询结果填充变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个网站可以轻松生成 ProFTPD 用户.现在,我正在保护我的网站免受 sql 注入攻击,为此,我将所有 mysqli 查询更改为带有准备好的语句的 pdo 查询.

                  但是我还是没弄明白,如何将sql查询结果保存在变量中.

                  <预><代码>...用户名=$_POST['用户名'];...$pdo = new PDO('mysql:host=localhost;dbname='db', 'root', 'PW');$query1= $pdo->prepare('select * from users where userid=:username');$query1->execute(array('username' => $username));foreach($query1 作为 $row){$result= $row->userid;}if($result == $username){echo "用户名已被占用";}

                  当我运行这段代码时,变量 $result 是 emtpy.

                  我希望有人能帮助我.

                  提前致谢.

                  解决方案

                  你应该使用 PDOStatement::fetch http://php.net/manual/en/pdostatement.fetch.php

                  I have a website to easily generate ProFTPD users. And now, I am securing my website against sql injection attacks, to do that I am changing all mysqli queries to pdo queries with prepared statements.

                  But I still couldn't find out, how to save sql query results in variable.

                  .
                  .
                  .
                  
                  username=$_POST['username'];
                  
                  .
                  .
                  .
                  
                  $pdo = new PDO('mysql:host=localhost;dbname='db', 'root', 'PW');
                  $query1= $pdo->prepare('select * from users where userid=:username');
                  $query1->execute(array('username' => $username));
                  
                  foreach($query1 as $row)
                  {
                   $result= $row->userid;
                  }
                  
                  
                  if($result == $username)
                  {
                   echo "Username is already taken";
                  }
                  

                  When I run this code, the variable $result is emtpy.

                  I hope somebody could help me.

                  Thanks in advance.

                  解决方案

                  You should use PDOStatement::fetch http://php.net/manual/en/pdostatement.fetch.php

                  这篇关于Php mysql pdo 查询:用查询结果填充变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:MySQLI 28000/1045 用户“root"@“localhost"的访问 下一篇:mysqli_select_db() 需要 2 个参数

                  相关文章

                  最新文章

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

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

                      • <bdo id='raAeh'></bdo><ul id='raAeh'></ul>
                      <legend id='raAeh'><style id='raAeh'><dir id='raAeh'><q id='raAeh'></q></dir></style></legend>