Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how insert a file into a mysql database ?

Status
Not open for further replies.

nicocl

Programmer
Jun 10, 2003
1
BE
how insert a file into a mysql database ?
Which type should I use ? with which attributs ? (binary) ?
How create my sql request ?
I try :
ALTER TABLE `user` ADD `certificat` VARCHAR BINARY NOT NULL
without any succes.
Error : You have an error in your SQL syntax near 'BINARY NOT NULL' at line 1

Thanks for your help

Nicolas

 
Hi,
You'll need to give the VARCHAR a length. E.G. VARCHAR(512) etc.

If this is a file you want to store you'll need to use the BLOB type, but it's not as easy as it looks. Getting the Data back out can be quite tricky.



William
Software Engineer
ICQ No. 56047340
 
I recommend that you store the name of the file in the database and store the actual contents of the file on your filesystem. As williamu has said, manipulating BLOB data is not easy.

Also, if you are creating a web-based application that will serve out those files, then you will have to write the code to fetch the file, set the correct content-type, and stream out the file. If you store the file on the filesystem, your web server already has code built in to do all that.

Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top