简体   繁体   中英

How to save a file to MySQL BLOB using PHP?

I'm trying to make a chat history system. So every time a person says hi to one another, they can also say something else. And each of those hi's, i wan't to add what they wrote into a history html file. Being something like this:

James Said: Hi Richard, i saw that hardware you told me about, it is compatible with our software!. 

At: 23 November 2011 - 23:09 UTC-08.
________________________________________________________________________________________

Richard Said: Nice!! let's start working with it this week, the project has to be finished before the end of the world.

At: 24 November 2011 - 09:23 UTC-08.
________________________________________________________________________________________

The html file i can build with php, but how do i save it to a MySQL BLOB? Without storing it in a directory (directly to the BLOB).

You're approach to this problem isn't really a good one.

If you try to store the data in a particular output format then you're in real trouble if you suddenly find you need the data in a different format.

You're much better off just storing the particulars of the conversation, and then generating the output to display from the stored conversation. That way you can easily present it in all kinds of formats you might need it in.

EDIT TO ADD:

Something else I should have mentioned (but forgot thanks to all the Christmas brandy ;) ), trying to store the conversation data in a single big block of data will negate most of the advantages using a relational database can confer in the first place. You couldn't, for example, easily store the timestamp of each line of the conversation, or search the database for particular items in the conversation. You could find workarounds of course, but given databases are already designed to solve those kinds of problems anyway, you'd just be wasting effort and your solution wouldn't measure up to what the database already provides.

由于它实际上不是二进制文件(Blob中的B),而是HTML,因此建议您使用MEDIUMTEXT类型并将其作为普通文本字段进行处理。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM