0

I am using FMDB, and i need to have a Database with the FirstName, and Photo of Students. So the name of the databaase will be Students, and the Attributes will be FirstName and Photo.

I know how to create, and Insert values to the database. But i don't know how to add images to the database.

I did a research and found out some ways that this could be implemented;

1.) Using BLOB - most of the people in forums has discouraged it (I don't know why) 2.) To save the path of the images

If i am saving images using BLOB then how can i do it ?

If i am saving the path of the images then how should i do it. Should i add all the images in the resource folder and then what should i do ?

NOTE: If i add several hundreds of images to the Resource folder in xCode what will the path of the file be ?

shajem
  • 2,111
  • 5
  • 22
  • 30
  • The reason it is discouraged has nothing to specifically with SQLite or FMDB. See this post http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay – Joe Mar 29 '12 at 14:45

1 Answers1

1

You should add your images to the Resources, but you should still save the image name in the database. This way, when you ask the database for the photo of the student, you will get the file name which you can use to get the photo from the application bundle:

// say your database returned 'student_45_photo.png'
NSString* imagePath = [[NSBundle mainBundle] pathForResource:@"student_45_photo" ofType:@"png"];
lawicko
  • 7,246
  • 3
  • 37
  • 49
  • WHat about the path to the Resource folder ? Do i have to save that as well in the DB ? – shajem Mar 29 '12 at 21:06
  • No, just save the photo name. As long as you have the photos in the application bundle, you don't need to worry about this. The *pathFroResource:ofType:* method will do the rest for you and will return the absolute path of the photo which you will be able to use for initializing UIImage for example. – lawicko Mar 30 '12 at 12:02