I was looking for answer for last 3 hours, and i don't know what to do. Here is the code:
function get_data($tablename)
{
try
{
$conn = $this->conn();
$stmt = $conn->prepare("SELECT * FROM :tablename ORDER BY id");
$stmt->bindParam(':tablename', $tablename, PDO::PARAM_STR);
$stmt->execute();
return $stmt;
}
catch (Exception $e)
{
echo "ERROR:" . $e->getMessage();
}
}
And here is the error:
ERROR:SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''products' ORDER BY id' at line 1
What I've done wrong?...