MySQL将二进制数据插入数据库无错误 [英] MySql insert binary data to db without errors
问题描述
我有问题.当我在php中这样插入时:
I have a problem. When I do an insert like so in php:
sql = "INSERT INTO mytable (id, value)
VALUES ('sds83','".$EncryptedString."')";
当我运行以下查询时,它有时可以工作,有时却不能.问题是有时$ EncryptedString包含如下字符:')') 这会导致语法错误. $ EncryptedString包含二进制数据,如何解决此问题?
When I run the following query it sometimes works and sometimes it doesn't. The problem is that sometimes the $EncryptedString contains characters like this: ')') which causes syntax errors. The $EncryptedString contains binary data, how can I go about this issue?
推荐答案
转义您的加密字符串
mysql_real_escape_string()调用MySQL的库函数 mysql_real_escape_string,将反斜杠添加到以下内容 字符:\ x00,\ n,\ r,\,',和\ x1a.
mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a.
请参见 StripSlashes
这篇关于MySQL将二进制数据插入数据库无错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!