On Thursday, March 7, 2002, at 07:16  PM, gregory hernandez wrote:

> can i insert the actual file (i.e. "document.txt", of course with it
> contents) into a mysql?
>
> in other words, i don't want to read the contents of the file and 
> insert the
> contents into a field in mysql.  i want to insert the actual file into 
> the
> database.  is this possible?

Yes you can, though it might be an inefficient way of doing it unless 
you have some reason to do it this way.  Look into the column type 
"BLOB" (binary large object), it lets you store binary large objects, 
such as images or files or anything, really.

Why inefficient?  Well, for one thing, BLOBs don't retrieve as quickly 
as regular fields, for reasons I don't altogether know.  Also, you won't 
be able to form a query to search for any characteristics of a BLOB, 
since MySQL will treat the BLOB as a BLOB and doesn't try to imagine 
what's inside it -- as opposed to, say, a VARCHAR column.  There is also 
a TEXT column type for very long text strings, and I forget whether or 
not the contents of these can be used in queries -- can someone please 
confirm this?  But basically, almost any other column type is valid 
subject matter for forming queries.

But for storing images and PDFs or other binary data, there's no other 
way.

Note that many MySQL wizards will recommend that instead of storing 
binary data in a database, use a filesystem to store the data and then 
use the database to create a sort of "directory" for quickly locating 
those files in the filesystem, remembering the path to the file or 
something.  I think this is how a lot of web sites incorporate graphic 
content in with their database (text) content (including mine).


Erik



----

Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to