note 98683 added to pdo.lobs
| From: | fabricelorente at osu1 dot php dot net | Date: | Wed, 30 Jun 2010 13:33:15 +0000 |
| Subject: | note 98683 added to pdo.lobs | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170600@lists.php.net to get a copy of this message | ||
insert the blob :
<?php
//connection a la base de donnee en utilisant le module PDO faisant partie de php
$db = new PDO('oci:dbname=...','user', 'pass');
//preparation de la requete
$stmt = $db->prepare("insert into TABLE1 (id, blob) " .
"VALUES (sequence1.nextval, EMPTY_BLOB()) RETURNING blob INTO :blob");
//association de la variable parametree et de la variable php contenant le fichier a inserer
$stmt->bindParam(':blob', $fp, PDO::PARAM_LOB);
//passage du fichier envoye par le client a la variable php
$fp = fopen($_FILES['nom']['tmp_name'], 'rb');
//debut de la transaction (obligatoire)
$db->beginTransaction();
//execution de la requete
$stmt->execute();
//commit obligatoire car le beginTransaction empeche l autocommit
$db->commit();
?>
display the blob :
<?php
$db = new PDO('oci:dbname=...,'user', 'pass');
$sql = "select blob from table1 where id=3";
$stmt = $db->prepare($sql);
$stmt->execute();
$stmt->bindColumn(1, $lob, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);
//le header indique au navigateur le type de binaire envoye (type mime)
header("Content-Type: image/jpeg");
fpassthru($lob);
----
Server IP: 69.147.83.197
Probable Submitter: 83.206.120.18
----
Manual Page -- http://www.php.net/manual/en/pdo.lobs.php
Edit -- https://master.php.net/note/edit/98683
Del: integrated -- https://master.php.net/note/delete/98683/integrated
Del: useless -- https://master.php.net/note/delete/98683/useless
Del: bad code -- https://master.php.net/note/delete/98683/bad+code
Del: spam -- https://master.php.net/note/delete/98683/spam
Del: non-english -- https://master.php.net/note/delete/98683/non-english
Del: in docs -- https://master.php.net/note/delete/98683/in+docs
Del: other reasons-- https://master.php.net/note/delete/98683
Reject -- https://master.php.net/note/reject/98683
Search -- https://master.php.net/manage/user-notes.php