PHP Doku:: Returns large object s contents - function.oci-lob-load.html

Verlauf / Chronik / History: (23) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAnbieterspezifische DatenbankerweiterungenOracle OCI8OCI8 FunktionenOCI-Lob->load

Ein Service von Reinhard Neidl - Webprogrammierung.

OCI8 Funktionen

<<oci_lob_is_equal

OCI-Lob->read>>

OCI-Lob->load

(PHP 5, PECL OCI8 >= 1.1.0)

OCI-Lob->loadReturns large object's contents

Beschreibung

string OCI-Lob::load ( void )

Returns large object's contents. As script execution is terminated when the memory_limit is reached, ensure that the LOB does not exceed this limit. In most cases it's recommended to use OCI-Lob->read instead.

Rückgabewerte

Returns the contents of the object, or FALSE on errors.

Siehe auch


3 BenutzerBeiträge:
- Beiträge aktualisieren...
pablo dot casado at layers dot com
3.02.2010 17:09
Reading a OCI-Lob by using the load() function will return only 2k chars, so you miss part of its contents.

For example:
<?php

$sql
= "BEGIN :res := getACLOB(id).getclobval(); END;";             
$stmt = oci_parse($conn, $sql);
$resVal = OCINewDescriptor($conn, OCI_D_LOB);
oci_bind_by_name($stmt, ":res", $resVal, -1, OCI_B_CLOB);
oci_execute($stmt);

$foo = $resVal->load();
// $foo will contain only 2k chars

// the following will neither work
$foo = $resVal->read( $resVal->size() );
// $foo will contain only 2k chars

?>

Use this instead:

<?php

$sql
= "BEGIN :res := getACLOB(id).getclobval(); END;";             
$stmt = oci_parse($conn, $sql);
$resVal = OCINewDescriptor($conn, OCI_D_LOB);
oci_bind_by_name($stmt, ":res", $resVal, -1, OCI_B_CLOB);
oci_execute($stmt);

$foo = "";
                   
while(!
$resVal->eof()){
   
$foo .= $resVal->read(2000);
}                   
// $foo will contain full contents of the CLOB
?>
FaLL3N at mail dot ru
25.12.2006 14:49
Ps. To prevent IE errors like 'File not found!' after downloading file from db I recommend to add next two lines into header:
header('Cache-Control: max-age=0');
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

With this, IE will open any file normally :)
FaLL3N at mail dot ru
25.10.2006 15:34
I'll give you example how to download a file from db without storing it on server's FS:
It works like this - point yor browser to index.php?name=file.ext
Just make sure that file "file.ext" exists in your db!

Code:

<?php

 $dbConnection
=ocilogon('user','pass','data.world'); //login stuff
 
$sql_SelectBlob='select document_body,filename from tdocuments where id=1'; //selecting a blob field named 'document_body' with id = 1
 
$statement=OCIParse($dbConnection,$sql_SelectBlob);

 
OCIExecute($statement) or die($sql_SelectBlob.'<hr>');

if(
OCIFetch($statement)) //if file exists
 
{
 
$a=OCIResult($statement,"DOCUMENT_BODY");
 }
header('Content-type: application/octet-stream;');
header('Content-disposition: attachment;filename='.$_GET['name']);

print
$a->load();
//browser promts to save or open the file
?>

Have fun!



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)