[SQL] [php] PDO - fonction BindParam
Bonjour :)
J'aimerai comprendre pourquoi le code ci-dessous me renvoie un résultat vide (la variable $recordsShadow contient un array vide, donc la requête ne renvoie rien !). Les 2 paramètres valorisés dans bindParam contiennent bien quelquechose...
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
$pdo = PDOCreator::getPDO($shadowcfg['bdd_dsn'], $shadowcfg['bdd_login'], $shadowcfg['bdd_password']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare('select * from shadow_vues sv '
.'left join shadow_colonnes sc on sv.id_vues = sc.id_vues '
.'where sv.vues_tag = :tagVue '
.'and sc.colonnes_tag in (:tagColonnes)');
$stmt->bindParam(':tagVue', $xml->tagVue);
$stmt->bindParam(':tagColonnes', $sql_tagColonnes);
if ($stmt->execute() === false) {
var_dump($stmt->errorInfo());
}
$recordsShadow = $stmt->fetchAll(); |
$sql_tagColonnes contient la chaîne :
" 'tag_col4', 'tag_col3', 'tag_col2', 'tag_col1' ".
Je me disais que c'était peut-être les quotes qui posaient problèmes dans le bindParam().
Il faut savoir que ça marche parfaitement quand je fais comme ci-dessous au lieu d'utiliser prepare() (idem quand je tape directement la requête dans ma base de données)
Code:
1 2
|
$stmt = $pdo->query('select * from shadow_vues sv left join shadow_colonnes sc on sv.id_vues = sc.id_vues where sv.vues_tag=\''.$tagVue .'\'and sc.colonnes_tag in ('.$sql_tagColonnes.')'); |
Merci :)
Cécilia.