Pdo更新功能

时间:2016-09-07 09:08:45

标签: mysql pdo

我的代码:

public static function duzenle($tablo,  $degerler, $kosul) {
    global $db;
    $prep = array();
    $aaa = array();
    foreach($degerler as $k => $v ) {
        $prep[$k.' = :'.$k] = $v;
        $aaa[":".$k ."= '".$v."'"] = $k;
    }
    $sth = $db->prepare("UPDATE ".$tablo." SET " . implode(', ',array_keys($prep)) . " WHERE ".$kosul."");
    $res = $sth->execute("".implode(', ',array_keys($aaa))."");
    return implode(', ',array_keys($aaa));
}

问题:

  

警告:PDOStatement :: execute()期望参数1为数组,   

中给出的字符串

1 个答案:

答案 0 :(得分:0)

我解决了问题

public static function duzenle($tablo,  $degerler, $kosul) {
    global $db;
    $prep = array();
    $aaa = array();
    foreach($degerler as $k => $v ) {
        $prep[$k.' = :'.$k] = $v;
    }

    $sth = $db->prepare("UPDATE ".$tablo." SET ".  implode(', ',array_keys($prep)) ."  WHERE ".$kosul."");
    $res = $sth->execute($degerler);
}