How to insert a file in MySQL database?

后端 未结 4 944
青春惊慌失措
青春惊慌失措 2020-11-29 05:18

I want to insert a file in MYSQL database residing on a remote webserver using a webservice.

My question is: What type of table column (e.g. varchar, etc.) will stor

4条回答
  •  星月不相逢
    2020-11-29 05:52

    You need to use BLOB, there's TINY, MEDIUM, LONG, and just BLOB, as with other types, choose one according to your size needs.

    TINYBLOB 255
    BLOB 65535
    MEDIUMBLOB 16777215
    LONGBLOB 4294967295
    (in bytes)
    

    The insert statement would be fairly normal. You need to read the file using fread and then addslashes to it.

提交回复
热议问题