0

I was using OCI_Connect to connect to my Oracle database. Because of some internal plicies, i need to change it to PDO.

With OCI_Connect, i can read LOB data from database with "->load()" function in the result, something like this:

$this->Conn = oci_connect($this->User, $this->Pass, $this->Name, 'AL32UTF8');
$sql = "select field from table";
$s = oci_parse($this->Conn, $sql);
$res = oci_fetch_array($s, OCI_ASSOC + OCI_RETURN_NULLS)
echo $res[0]['FIELD']->load();

and it worked very well.

Now i need to do the same stuff with PDO, and because all my queries may change the number and name of the fields, i cannot bind the variables before executing it.

What i'm using now to connect:

$dbTns = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = $server)(PORT = $port)) (CONNECT_DATA = (SERVICE_NAME = $service_name) (SID = $sid)))";
$paramArray = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
$this->PDO = new PDO("oci:dbname=" . $dbTns . ";charset=utf8", $db_username, $db_password, $paramArray );

With PDO, everything works fine, but i can't use the "->load()" function in the LOB field, as it does not exists here.

Is there an equivalent way to get the data after the query run?

Any suggestions are welcome. (yes, i did search for a solution before posting that question here)

Andre Duarte
  • 51
  • 1
  • 5
  • There is an example showing the use of `stream_get_contents()` in https://stackoverflow.com/a/56860194/4799035 I would much prefer using OCI8 with LOBS. Even more so now that the prefetch lob support was added, which can really help performance: https://pecl.php.net/package-changelog.php?package=oci8&release=3.2.1 – Christopher Jones Sep 03 '22 at 05:23
  • I did try with stream_get_contents() but i get an empty string. I also tried fpassthru() and in this case a get a "-1" instead of the contents. – Andre Duarte Sep 12 '22 at 13:03

0 Answers0