AW: [PHP-DB] Oracle8i large text (CLOB) inserts

From: Date: Wed, 11 Oct 2000 07:57:20 +0000
Subject: AW: [PHP-DB] Oracle8i large text (CLOB) inserts
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-3512@lists.php.net to get a copy of this message
Hi Chris, > $body=ereg_replace("'","''",$body); > > and now it seems I can insert things just fine. Will I run into > problems using this approach? Depends on the size of strings you want to insert; at least up to 8.0.5 you were limited to about 2.5K max length for literal strings. For longer texts, you must use the lob functions, i.e something like $clob = OCINewDescriptor($db, OCI_D_LOB); $q = "insert into eckdaten (id, beschreibung) values ('$eck_id', EMPTY_CLOB()) returning beschreibung into :clob"; if (!$r = OCIParse($db,$q)) fehler("Parse failed"); if (!OCIBindByName($r, ':clob', &$clob, -1, OCI_B_CLOB)) fehler("Bind failed"); if (!OCIExecute($r, OCI_DEFAULT)) fehler("execute failed"); if (strlen($beschreibung)) if (!$clob->save($beschreibung)) fehler("Saving LOB Data failed"); OCIFreeDescriptor($clob); OCIFreeStatement($r); OCIcommit($db); Using this aproach, you don't have to do any preparation of the data to be saved; single ' in the string are just fine. For all the other parameters, I normaly do automatic ' ==> '' replacement for all of them so I don't end up overlooking anything. function quote($val) { if (is_array($val)) { reset($val); $tmp = array(); while (list($k, $v) = each($val)) $tmp[$k] = quote($v); return($tmp); } else $val = ereg_replace("'", "''", $val); return ($val); } /* Oracle - quote all parameters */ if ($HTTP_POST_VARS) while (list($key, $val) = each($HTTP_POST_VARS)) $$key = quote($$key); if ($HTTP_GET_VARS) while (list($key, $val) = each($HTTP_GET_VARS)) $$key = quote($$key); Warning: the above only quotes the global set of parameters, not the HTTP_POST_VARS or HTTP_GET_VARS arrays (which - on the other hand - has the nice effect that you can still get to the unquoted value to use in LOB handling, see above) Bye, Martin "you have moved your mouse, please reboot to make this change take effect" -------------------------------------------------- Martin Bene vox: +43-316-813824 simon media fax: +43-316-813824-6 Nikolaiplatz 4 e-mail: mb@sime.com 8020 Graz, Austria -------------------------------------------------- finger mb@mail.sime.com for PGP public key

« previous php.db (#3512) next »