Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the text value of OCI-LOB in PHP

I have a column in the DB which is of type CLOB and I can't get the value in PHP as it is shown as

"resource id='204' type='"oci8 descriptor"'".

My adapter code:

 $this->_db->fetchRow(
                    $this->_db->select()
                        ->from(self::TABLE_NAME, array(
                            'BODY'
                        ))
like image 318
SMH Avatar asked Oct 20 '25 18:10

SMH


1 Answers

This is covered in The Underground PHP and Oracle Manual, page 234 "Fetching LOBs". Here's the example from that page:

<?php
$c = oci_connect('hr', 'welcome', 'localhost/XE');

$myblobid = 123;

$query = 'select blobdata from mybtab where blobid = :myblobid';
$s = oci_parse($c, $query);
oci_bind_by_name($s, ':myblobid', $myblobid);
oci_execute($s);
$arr = oci_fetch_array($s, OCI_ASSOC);
if (is_object($arr['BLOBDATA'])) { // protect against a NULL LOB
    $data = $arr['BLOBDATA']->load();
    $arr['BLOBDATA']->free();
    echo $data;
}
?>

I would advise reading the manual page yourself as there is important advice about avoiding memory leaks and returning LOB data as a string.

like image 192
timclutton Avatar answered Oct 22 '25 10:10

timclutton