5

I am trying to get a top info using an "where in" clause but if i use bindvalue or bindparam i don't get any results.

Here is my the query that doesn't give any results

$user2 = $db->prepare("Select top 100 memb_guid,memb___id,mail_addr,Gender,Country from MEMB_INFO where memb___id in (Select memb___id from MEMB_STAT where IP = :ip)");
$user2->bindValue(':ip','127.0.0.1',PDO::PARAM_STR);
$user2->execute();

If I use direct search without any bindvalues or param I get the results

$user2 = $db->prepare("Select top 100 memb_guid,memb___id,mail_addr,Gender,Country from MEMB_INFO where memb___id in (Select memb___id from MEMB_STAT where IP = '127.0.0.1')");
$user2->execute();

Can anyone help me out to use the bindvalue or param on this search 'where in' clause?

@PhilCross This is what I get when use var_dump:

object(PDOStatement)#4 (1) { ["queryString"]=> string(142) "Select top 100 memb_guid,memb___id,mail_addr,Gender,Country from MEMB_INFO where memb___id in (Select memb___id from MEMB_STAT where IP = :ip)"

Ps: I am using MSSQL Server

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mando Madalin
  • 193
  • 2
  • 3
  • 14
  • is `PDO::PARAM_STR` required ? – karthikr Jun 12 '13 at 14:27
  • Enable MySQL query log and see what is being run – Jessica Jun 12 '13 at 14:29
  • Put single quotes in your SQL query? `where IP = ':ip')` – David Starkey Jun 12 '13 at 14:31
  • 1
    PDO prepared statements doesn't require quotes around the values. @MandoMadalin can you do a `var_dump()` on $user2 directly after the first line in your first query? There could be a PDO error, which isn't being thrown due do your error handling. In addition, set your error handling for PDO to throw exceptions and wrap your `$db->prepare` code around a `try / catch` block. – Phil Cross Jun 12 '13 at 14:34
  • 3
    @David, prepared statements should not have quotes around the parameters. – Jessica Jun 12 '13 at 14:34
  • [PDO query fails but I can't see any errors. How to get an error message from PDO?](http://stackoverflow.com/a/15990858/285587) – Your Common Sense Jun 12 '13 at 17:00
  • @PhilCross This is what i get when use var_dump: object(PDOStatement)#4 (1) { ["queryString"]=> string(142) "Select top 100 memb_guid,memb___id,mail_addr,Gender,Country from MEMB_INFO where memb___id in (Select memb___id from MEMB_STAT where IP = :ip)" Ps: i am using MSSQL Server – Mando Madalin Jun 12 '13 at 14:50

1 Answers1

-2

the key of the bind value should be without ':'

and the bind value should be in variable.

$ip = '127.0.0.1';

$user2->bindValue('ip',$ip,PDO::PARAM_STR);

style007
  • 1
  • 1
  • Not true; in fact, the `:` prefix on parameter keys used to be mandatory in older versions of PDO, now in recent versions of PDO, it is optional. – Bill Karwin Apr 09 '14 at 17:17