PDO

pecl::PDO

AdvancedSearch | AreaMap ]

Search:

  Welcome   Installation   FAQ   User Notes   Links  
  User Notes   bindParam   DSN   exec   API differences   fetchCol   setAttribute   API  

Username:

Password:


Areas In
This Wiki

BEPHPUG

Conferences

emPHPower

LiveUser

Main

MDB2

PDO

PHPSVN

PHPTODO

RDBMS

WebBuilder2

bindParam

http://de2.php.net/pdo-prepare


<?php
$data = array(
 ':extension' => $extension,
 ':name' => $name
);
$stmt = $dbh->prepare("INSERT INTO CREDITS (extension, name) VALUES (:extension, :name)");
$stmt->execute($data);
?>

This code looks nice for people using Oracle. But most people do not use Oracle.

What about:


<?php
$data = array(
 'extension' => $extension,
 'name' => $name
);
$stmt = $dbh->prepare("INSERT INTO CREDITS (extension, name) VALUES (:extension, :name)");
$stmt->execute($data);
?>

(without ':')

Wez has mentioned that some RDBMS require the use of "@" versus ":" and that making the user apply the proper prefix makes it possible to directly send of the data to the RDBMS. However the performance improvements are likely to be hardly measureable. In constrast it is a major stumbling block for beginners. Also its likely to be a huge pain for developers as well. A very common case will be to store some metadata of the fields inside arrays (like is the field required, what type is the field etc) and key these arrays by column name and then build the SQL from that. Also it means that data fetched from result sets will not directly match up with the structure inside the data send to an execute. Therefore it is very likely that a large number of users will have to add additional code to append the colon just for PDO. This is even worse when using execute()'s ability to accept an array of data.

the above request is being implemented

---

I also noticed that bindParam() and bindColumn() are 1-indexed, which will raise inconviniences with people using arrays for example to stored the numeric indexes, similar in how having to add the ":" was a problem for people using arrays to store the string parameters.

Answer by Wez: "Passing an array with numeric indices to execute() expects 0 based indices, to cater for this case. Manually calling a bind function expects 1 based indices, as this is the convention for the majority of database APIs."

PDO:bindParam (62.214.182.78)
Tue, 26 Apr 2005, 09:51
[ Links | Source | History | RSS ]

This site powered by YaWiki 0.22 beta.


aidan [AT] php [DOT] net
2005-03-28 08:00:09 (14)
I agree, It's a pain prefixing.
davey [AT] php [DOT] net
2005-03-19 10:54:03 (13)
I also agree and brought this up to Wez also. - Davey
jlim [AT] natsoft [DOT] com [DOT] my
2005-03-17 10:58:08 (8)
Lukas - i agree! $data = array( 'extension' => $extension, 'name' => $name ); is better. John Lim

Add A Comment
Email:
*Comment:
Catpcha:
* denotes required field

Your comment will be added immediately; please check your comments, and be nice. :-)

Please use plain text only; HTML and PHP code will be converted to entities.

Your email address will be obfuscated with [AT] and [DOT] after you post your comment.