Ciao a tutti ho un problema sull'uso del metodo execute.
Questo il codice:
Codice PHP:
$this->pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$query = $this->pdo->prepare('SELECT :fields FROM :table');
$query->bindParam(':fields',$fields,PDO::PARAM_STR);
$query->bindParam(':table',$table,PDO::PARAM_STR);
if ($query->execute()) {
$this->data = $query->fetchAll(PDO::FETCH_OBJ);
var_dump($this->data);
}
L'execute mi restituisce false.
Se invece sostituisco un solo parametro...
Codice PHP:
$this->pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$query = $this->pdo->prepare('SELECT :fields FROM mytable');
$query->bindParam(':fields',$fields,PDO::PARAM_STR);
if ($query->execute()) {
$this->data = $query->fetchAll(PDO::FETCH_OBJ);
var_dump($this->data);
}
Ottengo...
codice:
array(30) { [0]=> object(stdClass)#4 (1) { ["pagetitle"]=> string(9) "pagetitle" } [1]=> object(stdClass)#5 (1) { ["pagetitle"]=> string(9) "pagetitle" } [2]=> object(stdClass)#6 (1) { ["pagetitle"]=> string(9) "pagetitle" }
Se non sostituisco niente...
Codice PHP:
$this->pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$query = $this->pdo->prepare('SELECT field1 FROM mytable');
if ($query->execute()) {
$this->data = $query->fetchAll(PDO::FETCH_OBJ);
var_dump($this->data);
}
Ottengo...
codice:
array(30) { [0]=> object(stdClass)#4 (1) { ["pagetitle"]=> string(8) "Homepage" } [1]=> object(stdClass)#5 (1) { ["pagetitle"]=> string(37) "Integrazione di un plugin per YouTube" } [2]=> object(stdClass)#6 (1) { ["pagetitle"]=> string(30) "La kuBOX al MIA 2009 di Rimini" }
Che è quanto vorrei ottenere usando però bindParam come nel primo caso.
Dove sbaglio?
Grazie.
Simone