Do I really ned bindParam?

Posted by sandelius on Stack Overflow See other posts from Stack Overflow or by sandelius
Published on 2010-03-18T05:00:03Z Indexed on 2010/03/18 5:01 UTC
Read the original article Hit count: 262

Filed under:
|
|

Hi there!

I'm trying to do a little PDO CRUD to learn some PDO. I have a question about bindParam. Here's my update method right now:

public static function update($conditions = array(), $data = array(), $table = '')
{
    self::instance();

    // Late static bindings (PHP 5.3)
    $table = ($table === '') ? self::table() : $table;

    // Check which data array we want to use
    $values  = (empty($data)) ? self::$_fields : $data;

    $sql     = "UPDATE $table SET ";
    foreach ($values as $f => $v)
    {
        $sql .= "$f = ?, ";
    }

    // let's build the conditions
    self::build_conditions($conditions);

    // fix our WHERE, AND, OR, LIKE conditions
    $extra = self::$condition_string;

    // querystring
    $sql   = rtrim($sql, ', ') . $extra;

    // let's merge the arrays into on
    $v_val = array_values($values);
    $c_val = array_values($conditions);
    $array = array_merge($v_val, self::$condition_array);

    $stmt  = self::$db->prepare($sql);
    return $stmt->execute($array);
} 

in my "self::$condition_array" I get all the right values from the ?. SO the query looks like this:

UPDATE table SET this = ?, another = ? WHERE title = ? AND time = ?

as you can see I dont use bindParams instead I pass the right values in the right order ($array) directly into the execute($array) method. This works like a charm BUT is it safe not use use bindParam here?

If not then how can I do it?

Thanks from Sweden

Tobias

© Stack Overflow or respective owner

Related posts about php

Related posts about pdo