I've reviewed this query several times but I do not think it's a mistake.
"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 ''dbg0' ('filename','src','hash','time') VALUES ('20170714214510th-freifejrfg.png' at line 1"
The PHP code is this:
private function insert_db($filename, $src, $hash) {
try {
$insert = $this->db->prepare("INSERT INTO :tabela ('filename','src','hash','time') VALUES (:filename, :src, :hash, :time)");
$insert->bindValue(':tabela', $this->table, PDO::PARAM_STR);
$insert->bindValue(':filename', $filename, PDO::PARAM_STR);
$insert->bindValue(':src', $src, PDO::PARAM_STR);
$insert->bindValue(':hash', $hash, PDO::PARAM_STR);
$insert->bindValue(':time', date('Y-m-d H:i:s'), PDO::PARAM_STR);
$insert->execute();
$this->lestId = $this->db->lastInsertId();
if ($this->lestId > 0) {
return TRUE;
} else {
$this->error = "Falha ao registrar imagem " . $insert->errorInfo();
return FALSE;
}
} catch (PDOException $e) {
$this->error = $e;
return FALSE;
}
}
I also made a function to return the query ready to test it:
public function sql($filename, $src, $hash) {
$this->sql = "INSERT INTO $this->table ('filename','src','hash','time') VALUES ('$filename', '$src', '$hash','".date('Y-m-d H:i:s')."')";
}
The same returned: INSERT INTO dbg0 ( filename
, src
, hash
, time
) VALUES ('20170714214510th-freifejrfg.png', '/ var / www / html / mysite / img / Posts / ',' ad7473acb6a4d5135dbb0a01a649ef48 ',' 2017-07-14 21:45:10 ') "I tested it straight in the base it is inserted without problems.