开发者

Write string with null bytes inside (PNG image) into MySQL in PHP

How do I write and read string (~200 开发者_开发知识库KB) with lots of 0 bytes inside into MySQL BLOB field?

This is not working:

$data = ... // PNG image raw data
$queryPart = "'" . addslashes($data) . "'";
... compose and execute query


The proper way to escape input data when using the legacy MySQL library is mysql_real_escape_string().


Even if they "can", databases are not made to stock binary files. It's more efficient to have in your table the path of the files on your server.


Use mysql_real_escape_string(), as it makes a call to the MySQL library to clean the given data.

http://php.net/manual/en/function.mysql-real-escape-string.php

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜