Can anyone help me
This works fine ::
$stmt = $this->conn->prepare("SHOW TABLES FROM db LIKE 'xyz'"); //tablename hardcoded
$stmt->execute();
$rows = $stmt->fetch(PDO::FETCH_ASSOC); //fetchAll
However if I try to bind my table name, as it will be dynamic in my script ::
$stmt = $this->conn->prepare("SHOW TABLES FROM db LIKE :tbl"); //tablename hardcoded
$tbl = "xyz";
$stmt->bindParam(":tbl", $tbl, PDO::PARAM_STR);
This gives error,
$stmt = $this->conn->prepare("SHOW TABLES FROM cens LIKE ?");
$tbl = "xyz";
$stmt->bindParam(1, $tbl, PDO::PARAM_STR);
This also gives error,
Error is
Fatal error: Uncaught exception 'PDOException' with message '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 '?' at line 1' in /opt/lampp/htdocs/PDO/test.php:132 Stack trace:
0 /opt/lampp/htdocs/PDO/test.php(132): PDO->prepare('SHOW TABLES FRO...')
I tried with quotes, both in query and in bind variable, but it didn't work
I want to bind the table name,