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
精彩评论