I am using PDO in PHP ... I have the following problem.
The following code does not work.
class A {
private $getUsersQuery = "SELECT * FROM users";
...
public function getUsers() {
$DBH = A::getDatabaseConnection();
try {
$query = $DBH->prepare($this->getUsersQuery);
...
} catch(PDOException $e) {}
}
}
But if I use the string it works.
$DBH->prepare("SELECT * FROM users");
Even if I use the echo outside the prepare() it works ...
echo $this->getUsersQuery; // Outputs the sql string.
Can someone point out what the problem might be.
Update :
Error :
SQLSTATE[42000]: Syntax error or access violation: 1065 Query was empty
Thanks