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

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

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

        <legend id='VanpQ'><style id='VanpQ'><dir id='VanpQ'><q id='VanpQ'></q></dir></style></legend>
      1. <tfoot id='VanpQ'></tfoot>

        PDO 'LIKE' 查询

        时间:2023-10-05
        <i id='svzH6'><tr id='svzH6'><dt id='svzH6'><q id='svzH6'><span id='svzH6'><b id='svzH6'><form id='svzH6'><ins id='svzH6'></ins><ul id='svzH6'></ul><sub id='svzH6'></sub></form><legend id='svzH6'></legend><bdo id='svzH6'><pre id='svzH6'><center id='svzH6'></center></pre></bdo></b><th id='svzH6'></th></span></q></dt></tr></i><div id='svzH6'><tfoot id='svzH6'></tfoot><dl id='svzH6'><fieldset id='svzH6'></fieldset></dl></div>

      2. <legend id='svzH6'><style id='svzH6'><dir id='svzH6'><q id='svzH6'></q></dir></style></legend>

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

          <tfoot id='svzH6'></tfoot>
            <tbody id='svzH6'></tbody>

                  <bdo id='svzH6'></bdo><ul id='svzH6'></ul>
                  本文介绍了PDO 'LIKE' 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  由于我刚开始使用 PDO 并且在偏离简单的 select from 查询时遇到问题,我想我最好在这里询问.

                  Since I'm new to using PDO and running into a problem when deviating from a simple select from query, I figured I'd best ask around here.

                  代码:

                    $sDbase = str_replace('`', '', $modx->db->config['dbase']);
                    $oPdo = new PDO("mysql:host=localhost;dbname=" . $sDbase . ";",   $modx->db->config['user'], $modx->db->config['pass']);
                    $oPdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                  
                    if(isset($_POST["search"]))
                    {
                      $sSearch = (!empty($_POST["search"])) ? mysql_real_escape_string($_POST["search"]) : "" ;
                    }
                  
                    $sSearch = 'beer' ;
                  
                    $sQry = <<< QRY
                      SELECT
                        contentid AS standid
                        ,value AS found
                        ,pagetitle
                        ,published
                      FROM 
                        modx_site_tmplvar_contentvalues
                      RIGHT JOIN
                        modx_site_content
                        ON
                        modx_site_content.id = modx_site_tmplvar_contentvalues.contentid
                      WHERE
                        ( tmplvarid = 41 OR tmplvarid = 40 )
                      AND
                        (value LIKE '%:search%'
                        OR
                        pagetitle LIKE '%:search%')
                      AND
                        published = '1'
                      ORDER BY
                        pagetitle
                      ASC
                  QRY;
                  
                    $oRes = $oPdo->prepare( $sQry );
                    $oRes -> bindParam( ":search", $sSearch );
                    $oRes -> execute() ;
                  
                    $aRow = $oRes->fetchAll();
                    $oRes -> closeCursor();
                  
                  
                    var_dump($aRow);
                  

                  变量 $sSearch 是我想在查询中绑定到 :search 的.对于这个例子,我已经在其中设置了一个值,但显然我想用一个 POST 变量替换它,这就是我首先要使用 PDO 的原因.

                  The variable $sSearch is what I want to bind to :search in the query. For this example, I've set a value in it, but obviously I want to replace that with a POST variable which is why I want to use PDO in the first place.

                  但是,该查询已经用 $sSearch 替换为一些搜索值进行了测试并且可以正常工作,但是现在我已经使用 PDO 执行相同的查询,并且得到一个空白结果.嗯,真的是一个空数组.

                  However, the query has been tested with $sSearch replaced by some searchvalue and works, but now I've used PDO to perform the same query, and I get a blank result. Well, an empty array really.

                  那么我在这里错过了什么?

                  So what am I missing here?

                  推荐答案

                  根据 Amelia 的评论,答案如下:

                  Per Amelia’s comment, here is the answer:

                  $sSearch = '%bier%' ;
                  

                  value LIKE :search
                  

                  成功了.

                  这篇关于PDO 'LIKE' 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用命名占位符设置 PDO/MySQL LIMIT 下一篇:如何防止 SQLITE SQLSTATE[HY000] [14]?

                  相关文章

                  最新文章

                    • <bdo id='6ZpLB'></bdo><ul id='6ZpLB'></ul>

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

                    1. <small id='6ZpLB'></small><noframes id='6ZpLB'>