ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-db
php-db
[PHP-DB] PDO prepared statement placeholders oddness (DB2)
by Daniel Krook other posts by this author
Feb 16 2006 6:36PM messages near this date
Re: [PHP-DB] Sessions help needed !!! | [PHP-DB] Oracle / Random errors
Hello folks,

I'm trying to pass an array of parameters to a statement I've prepared 
with '?' placeholders.  For example (all columns are varchar 50):

  $sql = 'INSERT INTO SOME_TABLE (COL1, COL2, COL3) VALUES (?, ?, ?)'
  $params = array('val1', 'val2', 'val3');

 
I've achieved the results I want with other interfaces using the following 
code:

Unified ODBC:
  $stmt = odbc_prepare($this-> db, $sql);
  $result = odbc_execute($stmt, $params);
 
The ibm_db2 extension:
  $stmt = db2_prepare($this-> db, $sql);
  $result = db2_execute($stmt, $params);
 
 
But I can't get either of the following to do the same with PDO:

This fills all columns with 'val3':
  $stmt = $this-> db->prepare($sql);
  $result = $stmt-> execute($params);
 
This fails with a segfault at bindValue (I can't be sure of the number of 
placeholders in $sql or how many values to manually bind from $params, so 
I do it in a loop (I've also tried a foreach)):
  $stmt = $this-> db->prepare($sql);
  $size = count($params);
  for ($i = 0; $i < $size; $i++) {
    echo $params[$i];
    $stmt-> bindValue($i + 1, $params[$i]);
  }
  $result = $stmt-> execute();
 
 
This is PHP 5.1.2 on SLES 9.   I don't see anything related in 
http://bugs.php.net/

Configure was
./configure --with-IBM_DB2 --with-pdo-odbc=ibm-db2,/home/db2inst1/sqllib 
--with-ibm-db2 --with-apxs2=/opt/IBMIHS/bin/apxs --enable-maintainer-zts

Any thoughts?


Thanks,
-Dan




Daniel Krook, Content Tools Developer
Global Production Services - Tools, ibm.com

http://bluepages.redirect.webahead.ibm.com/
http://blogpages.redirect.webahead.ibm.com/
http://bookmarks.redirect.webahead.ibm.com/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved