[PHP-DB] Re: Mysql PDO statement with params in HAVING problem
On 6/27/2013 7:51 AM, Alexander Pletnev wrote: Hi everyone, im new here, so please correct me if i created or formated topic incorrectly. I found a problem. I have a simple query for my needs: $stmt = $dbh->prepare("SELECT concat(first_name,' ',last_name) as full_name,t.* FROM `specialists` `t` HAVING full_name like '%john%'"); $stmt->execute(); while($row = $stmt->fetch()) { echo ''; var_dump($row); echo ''; } It works fine, until i add a param to my query: $stmt = $dbh->prepare("SELECT concat(first_name,' ',last_name) as full_name,t.* FROM `specialists` `t` HAVING full_name like '%:query%'"); $stmt->execute(); $query = 'londo'; $stmt->bindParam(':query',$query); while($row = $stmt->fetch()) { echo ''; var_dump($row); echo ''; } Now there is nothing in fetch(). Is it a bug ? Thanks. First - you prepare the query Second - you create and 'bind' the parameters to it Third - you execute the now completed query Fourth - you process the results. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Mysql PDO statement with params in HAVING problem
$stmt = $dbh->prepare("SELECT concat(first_name,' ',last_name) as full_name,t.* FROM `specialists` `t` HAVING full_name like '%:query%'"); How about '%:$query%' instead of '%:query%' ? Does that solve the problem? Thanks, On Thu, Jun 27, 2013 at 5:21 PM, Alexander Pletnev < pletnev.rusa...@gmail.com> wrote: > Hi everyone, im new here, so please correct me if i created or formated > topic incorrectly. > > I found a problem. I have a simple query for my needs: > > $stmt = $dbh->prepare("SELECT concat(first_name,' ',last_name) as > full_name,t.* FROM `specialists` `t` HAVING full_name like '%john%'"); > $stmt->execute(); > while($row = $stmt->fetch()) > { >echo ''; var_dump($row); echo ''; > } > > It works fine, until i add a param to my query: > > $stmt = $dbh->prepare("SELECT concat(first_name,' ',last_name) as > full_name,t.* FROM `specialists` `t` HAVING full_name like > '%:query%'"); > $stmt->execute(); > $query = 'londo'; > $stmt->bindParam(':query',$query); > while($row = $stmt->fetch()) > { >echo ''; var_dump($row); echo ''; > } > > Now there is nothing in fetch(). Is it a bug ? > > Thanks. > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
[PHP-DB] Mysql PDO statement with params in HAVING problem
Hi everyone, im new here, so please correct me if i created or formated topic incorrectly. I found a problem. I have a simple query for my needs: $stmt = $dbh->prepare("SELECT concat(first_name,' ',last_name) as full_name,t.* FROM `specialists` `t` HAVING full_name like '%john%'"); $stmt->execute(); while($row = $stmt->fetch()) { echo ''; var_dump($row); echo ''; } It works fine, until i add a param to my query: $stmt = $dbh->prepare("SELECT concat(first_name,' ',last_name) as full_name,t.* FROM `specialists` `t` HAVING full_name like '%:query%'"); $stmt->execute(); $query = 'londo'; $stmt->bindParam(':query',$query); while($row = $stmt->fetch()) { echo ''; var_dump($row); echo ''; } Now there is nothing in fetch(). Is it a bug ? Thanks. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php