开发者

How to insert image along with text in MySql?

开发者 https://www.devze.com 2023-04-07 16:36 出处:网络
I am trying to prepare a sample question paper preparation app. I am using tinyMCE editor and ajax-file-uploader plugin with it - as some questions may need images along with text.

I am trying to prepare a sample question paper preparation app. I am using tinyMCE editor and ajax-file-uploader plugin with it - as some questions may need images along with text. How do I store my questions that have both image 开发者_C百科and text into MySql using PhP?


I would suggest storing the image on some sort of NAS or some other location, and store the path to the image in the database along with the other data in respective fields.

You can store the image in the DB but it is not good idea to retrieve and present the image from the database to the user (It doesn't perform that great either). There might be a performance hit


MySQL handles images very well. You insert them in BLOBs. On the other hand you could store the image file name and path or a link, as text in your DB.

Which solution is the best depends on the requirements of your application. In general if you have a huge amount of images, your database will become huge and backing up will be slow. There might be a similar impact on your file system in order to store a huge amount of images.

Here is the interesting Microsoft To BLOB or not to BLOB paper, that will give you more information on the topic and even some metrics.


I would echo the answers already given by @harigm and @Costis Aivalis but if you really wanted to go "all out" and store both the HTML content and the images in the same BLOB why not have a look at RFC 2557 which allows you to place binary data (like images) in the document itself using the url scheme data:. To make this work you will need to parse your HTML once it gets back to your server and base64 encode all the images to be placed in the HTML, quite a lot of work for what would probably turn out to be little reward.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号