Ciao a tutti.
Mi sono arenato sui prepared statements. Ecco un esempio semplificato del mio problema:
Così funziona tutto
Codice PHP:
$this->stmt = $this->pdo->prepare('SELECT * FROM articoli');
$this->stmt->execute();
Mente così no:
Codice PHP:
$tabella = 'articoli';
$this->stmt = $this->pdo->prepare('SELECT * FROM :label');
$this->stmt->bindValue(':label', $tabella, PDO::PARAM_STR);
$this->stmt->execute();
//così nemmeno
$tabella = 'articoli';
$this->stmt = $this->pdo->prepare('SELECT * FROM :label');
$this->stmt->bindValue(1, $tabella, PDO::PARAM_STR);
$this->stmt->execute();
In entrambi i casì l'errore restituito è:
codice HTML:
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 ''articoli'' at line 1
Grazie per l'aiuto. 