$col = "*";$tablename = "test_data";$opt = "1";
$stmt = $conn->prepare("SELECT :col FROM `:tbl` WHERE :opt");
$stmt->bindValue(':col',$col, PDO::PARAM_STR);
$stmt->bindValue(":tbl",$tablename, PDO::PARAM_STR);
$stmt->bindValue(':opt',$opt, PDO::PARAM_STR);
it got error when i do $stmt->execute();
The error is about the sql error.
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]
This got no error if I din't bind the :tbl.
Means that i can run this if I write it as below
$col = "*";$opt = "1";
$stmt = $conn->prepare("SELECT :col FROM `test_data` WHERE :opt");
$stmt->bindValue(':col',$col, PDO::PARAM_STR);
$stmt->bindValue(':opt',$opt, PDO::PARAM_STR);