PDO prepared statement placeholders oddness (DB2)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux