Page 1 of 1

PDO bindValue problem

Posted: Sat Nov 01, 2008 6:13 pm
by spamyboy

Code: Select all

function update_user($user_id, $array) {
        $result = $this->db->prepare("UPDATE `gcms_user`
                                     SET ?=?
                                     WHERE `user_id`=?;");
            $result->bindValue(3,   $user_id,   PDO::PARAM_INT);
        foreach ($array as $key=>$value) {
            $result->bindValue(1,   $key,       PDO::PARAM_STR); // Problem here
            $result->bindValue(2,   $value,     PDO::PARAM_STR);
            $result->execute();
        }
    }
Problem is basic. Query is generated like "UPDATE `gcms_user` SET 'key_or_1_var'='value_or_2_var' WHERE `user_id`='#id#';"
So basically key_or_1_var is taken as variable since it is with '' and how to change that to ``?

Re: PDO bindValue problem

Posted: Mon Nov 03, 2008 4:47 pm
by infolock
I'd be interested to see the array you are passing to it first of all.

Secondly, I'd also be interested in seeing the SQL that is generated from this to see what it looks like as well.