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

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

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

        PDO/PHP - 检查行是否存在

        时间:2023-09-21

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

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

        1. <tfoot id='oiYkO'></tfoot>
            <tbody id='oiYkO'></tbody>
            <bdo id='oiYkO'></bdo><ul id='oiYkO'></ul>
              <legend id='oiYkO'><style id='oiYkO'><dir id='oiYkO'><q id='oiYkO'></q></dir></style></legend>

                  本文介绍了PDO/PHP - 检查行是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想要一个条件,以防该行根本不存在.

                  I want to have a condition incase the row doesn't exist at all.

                  $stmt = $conn->prepare('SELECT * FROM table WHERE ID=?');
                  $stmt->bindParam(1, $_GET['id'], PDO::PARAM_INT);
                  $stmt->execute();
                  $row = $stmt->fetch(PDO::FETCH_ASSOC);
                  

                  尝试了 if (count($row) == 0)if($stmt->rowCount() <0) 但它们都不起作用.

                  Tried if (count($row) == 0) and if($stmt->rowCount() < 0) but none of them works.

                  推荐答案

                  直接查看返回值即可.

                  $stmt = $conn->prepare('SELECT * FROM table WHERE ID=?');
                  $stmt->bindParam(1, $_GET['id'], PDO::PARAM_INT);
                  $stmt->execute();
                  $row = $stmt->fetch(PDO::FETCH_ASSOC);
                  
                  if( ! $row)
                  {
                      echo 'nothing found';
                  }
                  
                  /*
                  $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // Same here
                  if( ! $rows)
                  {
                      echo 'nothing found';
                  }
                  */
                  

                  如果您要求检查而不获取,那么只需让 MySQL 返回 1(或使用 COUNT() 命令).

                  If you are asking about checking without fetching then simply have MySQL return a 1 (or use the COUNT() command).

                  $sql = 'SELECT 1 from table WHERE id = ? LIMIT 1';
                  //$sql = 'SELECT COUNT(*) from table WHERE param = ?'; // for checking >1 records
                  $stmt = $conn->prepare($sql);
                  $stmt->bindParam(1, $_GET['id'], PDO::PARAM_INT);
                  $stmt->execute();
                  
                  if($stmt->fetchColumn()) echo 'found';
                  

                  这篇关于PDO/PHP - 检查行是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 PDO 清理输入? 下一篇:如何读取“fetch(PDO::FETCH_ASSOC);"

                  相关文章

                  最新文章

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

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

                      <tfoot id='NzmEX'></tfoot>

                    1. <legend id='NzmEX'><style id='NzmEX'><dir id='NzmEX'><q id='NzmEX'></q></dir></style></legend>
                      • <bdo id='NzmEX'></bdo><ul id='NzmEX'></ul>