0

does anyone understand why the code is returning empty array

$name = 'login';
$data = 'user2';
$sql = 'SELECT :name FROM test.users WHERE :name=:data';
$sth = $dbh->prepare($sql);
$sth->execute([':name' => $name, ':name' => $name, ':data' => $data]);
$res = $sth->fetchAll();
var_dump($res);
BlackNetworkBit
  • 768
  • 11
  • 21
  • Also, if you're trying to select a value you already know (if this *could* return anything, it would just be the value contained in `$data`), you're probably looking for something like `Select Count()...` – iainn Sep 06 '18 at 10:09
  • 1
    BTW, if your previous questions __have correct answers__, that help you - __accept__ such answers. – u_mulder Sep 06 '18 at 10:21

1 Answers1

5

Two reasons:

  • You cannot bind field name.
  • You cannot use placeholder more than once (:name)
u_mulder
  • 54,101
  • 5
  • 48
  • 64