Gewusst wie: einfügen von array in mysql mit PDO und bindParam?

Ich bin mit dem folgenden code. Der code funktioniert, aber ich will es ändern, so dass es verwendet bindparam

try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
$stqid=array();

    for ($i=0; $i<$array_count; $i++){
    $stqid[$i][0]=$lastInsertValue;
    $stqid[$i][1]=$qid[$i][0];
    $stqid[$i][2]=$qid[$i][1];
    }

$values = array();
    foreach ($stqid as $rowValues) {
        foreach ($rowValues as $key => $rowValue) {
        $rowValues[$key] = $rowValues[$key];  
        }

    $values[] = "(" . implode(', ', $rowValues) . ")";
    }

$count = $dbh->exec("INSERT INTO qresults(instance, qid, result) VALUES  ".implode (', ', $values)); 
$dbh = null;
}
catch(PDOException $e){
    echo $e->getMessage();
}

Ersetzte ich die folgende

$count = $dbh->exec("INSERT INTO qresults(instance, qid, result) VALUES  ".implode (', ', $values)); 

mit

$sql = "INSERT INTO qresults (instance, qid, result) VALUES (:an_array)";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':an_array', implode(',', $values),PDO::PARAM_STR);
$stmt->execute();

aber das einfügen nicht mehr funktioniert (ich bekam keine Fehlermeldungen, obwohl).

FRAGE: Was mache ich falsch? Wie kann ich den code neu schreiben zu verwenden bindParam?

InformationsquelleAutor TryHarder | 2012-03-25
Schreibe einen Kommentar