Re: BLOB Support in DB

From: Date: Wed, 10 Jul 2002 15:20:30 +0000
Subject: Re: BLOB Support in DB
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-1840@lists.php.net to get a copy of this message
David, Hopefully the following code will help. I found that working on windows always makes something difficult. "rb" is important because it then knows to read it as a binary file. I included quite a bit of code to help you get a feeling for what I did... Good Luck.... Michelle //get the contents of the file, adding slashes to escape characters that will cause a problem. $contents =addslashes(fread (fopen($filename, "rb"), $filesize));//rb is used in WIN NT //get the file creation time $fileCreateTime = filectime( $filename); //configure file creation time to conform to database field specs $date = date("Y-m-d H:i:s", $fileCreateTime); //build insert string for database. $insertString = "INSERT INTO tblwavfile (ID, WavFile, WavName, CreationDate, WavSize, Type) VALUES ( '$ID', '$contents', '$realname', '$date', '$filesize', '$filetype' )"; MYSQL_CONNECT(DB, USER, PASSWORD); mysql_select_db("tranDB"); $result=MYSQL_QUERY($insertString); $id= mysql_insert_id(); if ($id > 0) { printf ("Database id for your file: %s<br>\n", $id); } else { printf ("Your file was not successfully inserted!\n"); } //here , must delete file created with upload... $unlinksuccess = unlink($filename); if ($unlinksuccess) { //echo "The file($filename) was deleted! <hr>"; }else { echo "The file ($filename) was not deleted!<hr>"; } MYSQL_CLOSE(); } } ----- Original Message ----- From: David Dahl To: PEAR Sent: Wednesday, July 10, 2002 11:07 AM Subject: Re: [PEAR] BLOB Support in DB My common.php: ($Id: common.php,v 1.3 2002/05/09 12:29:53 ssb Exp $) has the same prepare() method as your version... I am not to confident in changing any PEAR files, as it might get me in trouble later if I upgrade or something. how should I form my SQL to insert a BLOB? something like this? insert into people (name, photo) values ('John', '/tmp/userfile') regards, David Dahl On Wed, 2002-07-10 at 09:51, Michelle Manning wrote: > Hi David, > We had a lot of problems using pear DB for Blobs and found a couple of things. > 1. in common.php in DB the split is used, but this actually can cause some problems. > so we used preg_split and had to change the & to another character as I was testing > using bit comparison. With that change...it seems to work... > ($Id: common.php,v 1.59.2.3 2001/11/13 01:26:42 ssb Exp $) This is the version that I am > talking about. > > Let me know if there is anything else that would help with BLOBs - we have major work with > wavs and images... > > In DB\common.php > function prepare($query) > { > $tokens = preg_split("/[\^\?\!]/", $query); //changed this line... > $token = 0; > $types = array(); > > for ($i = 0; $i < strlen($query); $i++) { > switch ($query[$i]) { > case '?': > $types[$token++] = DB_PARAM_SCALAR; > break; > case '^': > $types[$token++] = DB_PARAM_OPAQUE; > break; > case '!': > $types[$token++] = DB_PARAM_MISC; > break; > } > } > > Michelle > ----- Original Message ----- > From: David Dahl > To: PEAR > Sent: Wednesday, July 10, 2002 10:32 AM > Subject: [PEAR] BLOB Support in DB > > > Hi: > > I was just wondering how things are going with BLOB support in DB? > > Thanks > > David Dahl > > > -- > PEAR General Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.pear.general (#1840) next »