Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pulling Oracle CLOB's different than VARCHAR2?

With MySQL, I'm able to store large blocks of text in a TEXT column, pull like I would any other column type with no problem.

It seems when I try to do the same with CLOB on Oracle, I get errors.

Here's where I'm pulling:

<?php
$comments = 'SELECT q2_other, q4_comments, q9_describe, q10, q11_comments, q12_describe, additional_comments FROM exit_responses
             WHERE sdate BETWEEN \'' . $start . '\'
             AND \'' . $end . '\'';

$comments_results = oci_parse($conn, $comments);
oci_execute($comments_results);

while($row = oci_fetch_assoc($comments_results)){
  if($row['Q2_OTHER'] != null){
  echo '<div class="response">';
    echo '<div class="info-bar">';
      echo '<h5 class="date">' , date('F j, Y',strtotime($row['SDATE'])) , '</h5>';
      echo ($_GET['names'] == 1) ? '<h5 class="name">' . $row['f_name'] . ' ' . $row['l_name'] . ' - ' . $row['title'] . ' - ' . $row['emp_type'] . '</h5>' : '';
      echo '<div class="clear"></div>';
    echo '</div>';
    echo '<div class="comments">' , $row['q2_other'] , '</div>';
    echo '<div class="clear"></div>';
  echo '</div>';
  }
}
?>

...and here is what I'm getting when I try to print_r() $row within the while() loop:

[Q2_OTHER] => OCI-Lob Object
        (
            [descriptor] => Resource id #17
        )

...(along with the other columns in the query)

Is there something special I need to be doing with CLOBS or is my syntax just off a bit.

Thanks :)

like image 293
Will Avatar asked Feb 25 '23 22:02

Will


2 Answers

For LOB columns OCI will return OCI-Lob object, on which you have to call load() or read(int bytes) to get the contents:

$clob_contents = $row['Q2_OTHER']->load();
like image 140
vls Avatar answered Mar 07 '23 10:03

vls


or you can use OCI_RETURN_LOBS flag like $row = oci_fetch_array($connection_id, OCI_ASSOC | OCI_RETURN_LOBS) to fetch CLOB like VARCHAR2:

$row['clob_field_name']

like image 33
Kerb Avatar answered Mar 07 '23 11:03

Kerb