note 24742 deleted from function.ocibindbyname by sixd
| From: | sixd@php.net | Date: | Wed, 20 Nov 2013 19:47:58 +0000 |
| Subject: | note 24742 deleted from function.ocibindbyname by sixd | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197588@lists.php.net to get a copy of this message | ||
Note Submitter: chris_se at gmx dot net
----
Be warned if you use this function with a fixed-width character field:
If you have a table with the following fields:
create table personal_data (
name char(20) not null,
street char(50),
city char(50),
primary key (name) using index
);
Now, if you want to update a column without OCIBindByName, you may write
$stmt = OCIParse ($conn, "update personal_data set street = '$street' where name =
'$name'");
$res = OCIExecute ($stmt);
OCIFreeStatement ($stmt);
If you want to use OCIBindByName, the following will _only_ work, if the contents of $name has
always the same length as field:
$stmt = OCIParse ($conn, "update personal_data set street = :STREET where name = :NAME");
OCIBindByName ($stmt, ":STREET", &$street, 50);
OCIBindByName ($stmt, ":NAME", &$name, 20);
$res = OCIExecute ($stmt);
OCIFreeStatement ($stmt);
(this will not produce any error, it's simply that the where-clause will never get true if the
contents of $name is not as long as the field itself)
To make this work, you have to trim the field:
$stmt = OCIParse ($conn, "update personal_data set street = :STREET where trim(name) =
:NAME");
OCIBindByName ($stmt, ":STREET", &$street, 50);
OCIBindByName ($stmt, ":NAME", &$name, 20);
$res = OCIExecute ($stmt);
OCIFreeStatement ($stmt);