note 24742 added to function.ocibindbyname

From: Date: Tue, 27 Aug 2002 15:44:33 +0000
Subject: note 24742 added to function.ocibindbyname
Groups: php.notes 
Request: Send a blank email to php-notes+get-35737@lists.php.net to get a copy of this message
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); -- http://www.php.net/manual/en/function.ocibindbyname.php http://master.php.net/manage/user-notes.php?action=edit+24742 http://master.php.net/manage/user-notes.php?action=delete+24742 http://master.php.net/manage/user-notes.php?action=reject+24742

« previous php.notes (#35737) next »