note 84321 added to pdostatement.fetch

From: Date: Wed, 09 Jul 2008 12:21:58 +0000
Subject: note 84321 added to pdostatement.fetch
Groups: php.notes 
Request: Send a blank email to php-notes+get-141295@lists.php.net to get a copy of this message
I spent some hours trying to find out how to manipulate with BLOB fields using PDO. Remember that you can't retreive BLOB data using something like this : <?php $sql = 'SELECT * FROM sometable LIMIT 1'; $stmt = $dbh->prepare($sql); $stmt->execute(); $stmt->setAttribute(PDO::FETCH_ASSOC); $row = $stmt->fetch(); $myFile = $row['file']; ?> Instead of this you should try following approach: <?php $sql = "SELECT mime, file FROM sometable LIMIT 1"; $stmt = $dbh->prepare($sql); $stmt->execute(); $stmt->bindColumn(1, $mime,); $stmt->bindColumn(2, $file, PDO::PARAM_LOB); $stmt->fetch(); header('Content-type: '.$mime); print $file; ?> ---- Server IP: 195.54.192.44 Probable Submitter: 127.0.0.1 ---- Manual Page -- http://www.php.net/manual/en/pdostatement.fetch.php Edit -- https://master.php.net/note/edit/84321 Del: integrated -- https://master.php.net/note/delete/84321/integrated Del: useless -- https://master.php.net/note/delete/84321/useless Del: bad code -- https://master.php.net/note/delete/84321/bad+code Del: spam -- https://master.php.net/note/delete/84321/spam Del: non-english -- https://master.php.net/note/delete/84321/non-english Del: in docs -- https://master.php.net/note/delete/84321/in+docs Del: other reasons-- https://master.php.net/note/delete/84321 Reject -- https://master.php.net/note/reject/84321 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#141295) next »