0

In this case I bound one named parameter, :var.

$var = 'John Doe';
$query = $db->prepare("SELECT * from `users` where user = :var");
$query->bindParam(":var", $var);
$query->execute();

But now, I need to bind the single named parameter twice,

$var = 'John Doe';
$query = $db->prepare("SELECT * from `users` as u left join `user_group` as ug on u.user_id = ug.user_id where u.user = :var and ug.user_name = :var");
$query->bindParam(":var", $var);
$query->execute();

So, my question is that can i set bindParam single time or multi-time ?

Script47
  • 14,230
  • 4
  • 45
  • 66
Jaydeep Mor
  • 1,690
  • 3
  • 21
  • 39
  • Just give it a try and see if it works with one, however, IIRC, it will throw up an error if you did it with less number of variables in `bindParam` than your query. – Script47 May 18 '18 at 04:12
  • You aren't using `mysqli` please keep the tags appropriate. See https://stackoverflow.com/questions/2432084/pdo-parameterized-query-reuse-named-placeholders. – user3783243 May 18 '18 at 04:12
  • http://php.net/manual/en/pdostatement.bindparam.php#example-1046 check first example – Jaydp May 18 '18 at 04:13
  • 1
    @Jaydp I can't see where the OP is meant to be looking in that link, can you clarify what specifically in the first example? – Script47 May 18 '18 at 04:14

0 Answers0