I have a little PHP script which just needs to get all the rows from a table in a SQLite database.
The name of the table is always something like 174597131028398082-199534472775860224
.
This name is composed from two variables (sid
and cid
) which are defined through the parameters of a GET request. The problem is that instead of returning all the rows (which I would display later in the script), I get this error : SQLSTATE[HY000]: General error: 1 no such table: :sid-:cid
.
It seems like PHP does not replace :sid
and :cid
with the correct values. I've seen another thread about a similar problem, but I still can't get it working.
Here's my code :
$query = "SELECT * FROM `:sid-:cid`;";
$queryparams = array(
':sid' => $_GET['sid'],
':cid' => $_GET['cid']
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($queryparams);
} catch(PDOException $ex) {
die($ex->getMessage());
}
Also, here is how I connect to the database :
try {
$db = new PDO("sqlite:scores.db");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
} catch(PDOException $ex) {
die($ex->getMessage());
}