PDO 'LIKE' query

Apanazy

New Member
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.The code:\[code\] $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 ASCQRY; $oRes = $oPdo->prepare( $sQry ); $oRes -> bindParam( ":search", $sSearch ); $oRes -> execute() ; $aRow = $oRes->fetchAll(); $oRes -> closeCursor(); var_dump($aRow);\[/code\]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 on the first place.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, i get a blank result. Well.. an empty array really.So what am i missing here?Thanks already for your help.
 
Back
Top