RE: [PHP-DB] Problems using Oracle CLOB <---- Solved!!!!
| From: | Jadiel Flores | Date: | Tue, 06 May 2003 16:15:23 +0000 |
| Subject: | RE: [PHP-DB] Problems using Oracle CLOB <---- Solved!!!! | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27557@lists.php.net to get a copy of this message | ||
Well, I finally was able to insert and update clobs using sql but it's a little complicate, I'm sending my codes to the list in case that someone else needs them.
The code below is what you need to insert data into clobs:
$DBlink = ocilogon($DBUser,$DBPwd,$DBName); $Clob = OCINewDescriptor($DBlink, OCI_D_LOB); $query = "INSERT INTO TableName (ContentID, Content) VALUES ($NewID, EMPTY_CLOB()) returning Content into :THE_CLOB"; $DBresult = ociparse($DBlink, $query); OCIBindByName($DBresult, ":THE_CLOB", &$Clob, -1, OCI_B_CLOB); OCIExecute($DBresult, OCI_DEFAULT); $Clob->save($NewContent); if(OCICommit($DBlink)){To update CLOB's: $query = "UPDATE TableName SET Content = EMPTY_CLOB() WHERE ContentID = $ID returning Content into :THE_CLOB"; $DBresult = ociparse($DBlink, $query); $Clob = OCINewDescriptor($DBlink, OCI_D_LOB); OCIBindByName($DBresult, ":THE_CLOB", &$Clob, -1, OCI_B_CLOB); OCIExecute($DBresult, OCI_DEFAULT);$result = true;} else{$result = false;} OCILogOff ($DBlink);
$Clob->save($NewContent); if(OCICommit($this->DBlink)){
$this->resultado = true;} else{
$this->resultado = false;} To read CLOBs: $query = "SELECT Content FROM TableName WHERE ContentID = $ID"; $stmt=OCIParse($DBlink,$query); OCIExecute($stmt,OCI_DEFAULT); $result = array(); $x=0; while(OCIFetch($stmt)){
$ncols=OCINumCols($stmt);
$result[$x] = array();
for($i=1,$j=0;$i<=$ncols;$i++,$j++){
$column_name=OCIColumnName($stmt,$i);
if(is_object($tmp=OCIResult($stmt,$i))&&OCIColumnType($stmt,$i)=='CLOB'){
$column_value=$tmp->load();
}else{
$column_value=$tmp;
}
$result[$x][$j] = $column_value;
}
$x++;
}
OCICommit($DBlink);
It returns a bidimensional array ($result) containing CLOB's content
It's a little bit hard to understand because I'm using all this code inside a class I made to create all the queries, I had to change some codes and maybe it contains some errors, but I guess you can get the idea to manipulate CLOBs with this codes.
Jadiel Flores
-------------------------
http://www.abargon.com
jflores@abargon.com
(52-55) 52-29-80-34