#Written by Jen Chen #Copyrighted by Jen Chen #CS 122 #Winter 2005 #Lectures: How to store a binary type object into mysql tables. (1) Declare a field of type blob in your table. Before you proceed to the next step, make sure that the folder(s) that contain the binaries (pictures, in this case) is readable by ALL. Therefore it is a good advice NOT to store these files under your home directory for security reasons. Choose another directory to store these objects then chmod to allow this directory to be READABLE by ALL. Also all the files under this directory have to be READABLE by ALL. EX: cp *.jpg /tmp/ chmod 744 /tmp/*jpg (2) Use the function load_file('path') to load the file into your table. Note that you are not able to read the contents of this object using the SELECT statement. Since this object is of type binary. ========================================== EX: CREATE TABLE pics ( Name varchar(25) NOT NULL default '', Description varchar(50) default NULL, pics mediumblob, ID mediumint(9) NOT NULL auto_increment, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 insert into pics values('ac422','JPEG file',load_file('/tmp/ac422.jpg'),1); select * from pics; ========================================== OR (1) Create a field in your table that points to the path of the object(s). (2) Store the paths of the objects in your tables. (3) Use GD library to retrieve these objects from the web. By using this method you can read the paths point to the storage of these objects. CREATE TABLE picsStore ( Name varchar(25) NOT NULL default '', Description varchar(50) default NULL, path varchar(50) default NULL, ID mediumint(9) NOT NULL auto_increment, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 insert into picsStore values('ac422','JPEG file','/tmp/ac422.jpg',1); select * from picsStore;