Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:15700 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57233 invoked by uid 1010); 31 Mar 2005 15:28:43 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 57218 invoked from network); 31 Mar 2005 15:28:43 -0000 Received: from unknown (HELO pb1.pair.com) (127.0.0.1) by localhost with SMTP; 31 Mar 2005 15:28:43 -0000 X-Host-Fingerprint: 81.169.182.136 h59705.serverkompetenz.net Linux 2.4/2.6 Received: from ([81.169.182.136:57695] helo=strato.aixcept.de) by pb1.pair.com (ecelerity HEAD r(5268)) with SMTP id 4C/B8-22409-B271C424 for ; Thu, 31 Mar 2005 10:28:43 -0500 Received: from localhost (localhost [127.0.0.1]) by strato.aixcept.de (Postfix) with ESMTP id 34AF135C1D0; Thu, 31 Mar 2005 17:34:10 +0200 (CEST) Date: Thu, 31 Mar 2005 10:28:38 -0500 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1383893714.20050331102838@marcus-boerger.de> To: "Thies C. Arntzen" Cc: internals@lists.php.net In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] pdo: binding variables supplied to execute() is NotVeryUseful(tm)... From: mail@marcus-boerger.de (Marcus Boerger) Hello Thies, Friday, March 25, 2005, 1:55:30 PM, you wrote: > 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";-) We could easily add this behavior and i think it makes somewhat sense. It just looks a bit like __wakepup/__sleep. The only 'but' is that i suggest the behavior has its own method like 'bindParamArray'. If you cannot work out a patch feel free to contact me. Maybe i'll find some time during the conf. -- Best regards, Marcus mailto:mail@marcus-boerger.de