hi,

pdo hat it's own query-parser, named variables are prefixed with a colon... so far - so nice...

i have a function called insert which is called like this:

$db->insert('some_table', array('name' => $name, 'age' => $age));

it's implemented like this:

function insert($table, $values) {
    $column_names = array_keys($values);
    $col_list = implode(', ', $column_names);
    $bind_list = implode(', :', $column_names);

    $sql = "insert into $table ($col_list) values ($bind_list)";
        
    $stmt = $this->prepareStatement($sql);

    // works:
    // this is how it has to be done..
    //
    foreach ($values as $col => $val) {
        $stmt->bindParam(":$col", $values[ $col ]);
    }
    $stmt->execute();

    // doesn't work
    // and this is how i would like it instead
    //
    # $stmt->execute($values);
}


and this is 'cause pdo _expects_ the user to prefix the bound variables with a colon. grr...


ppls, lets change it before it's too late. this "tiny bit" makes binding harder than it should be, and we all know and understand that all user of php should use bound variables all the time!

suggestion: auto-trim a leading colon from the internal binding tables. that way "oldish" code would not break...


re, thies

PS: looking into that right now - hopefully "patch follows";-)

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to