mysql_real_escape_string()函数的作用是:转义 SQL 语句中使用的字符串中的特殊字符,并考虑到连接的当前字符集。可对下列字符进行操作:\x00 \n \r \ ' " \x1a 如果函数执行成功,将返回转义后的字符串;如果执行失败将返回False。Syntax 语法 mysql_real_escape_string(string,connection) string Required. Specifies the string to be escaped 必要参数。制定需要执行转义操作的字符串 connection Optional. Specifies the MySQL connection. If not specified, the last connection opened by mysql_connect() or mysql_pconnect() is used. 可选参数。指定MySQL连接。如果不指定该参数,那将默认使用通过mysql_connect()函数或mysql_pconnect()函数最后一次打开的连接
\n
\r
\
'
"
\x1a
如果函数执行成功,将返回转义后的字符串;如果执行失败将返回False。Syntax
语法
mysql_real_escape_string(string,connection) string Required. Specifies the string to be escaped
必要参数。制定需要执行转义操作的字符串
connection Optional. Specifies the MySQL connection. If not specified, the last connection opened by mysql_connect() or mysql_pconnect() is used.
可选参数。指定MySQL连接。如果不指定该参数,那将默认使用通过mysql_connect()函数或mysql_pconnect()函数最后一次打开的连接
1. InitDatabase();
2. char query[1000]={"Insert into mytable values("};
3. char *end;
4. end=query;
5. end+=30;
6. end = strmov(query,"INSERT INTO mytable values(");
7. *end++ = '\'';
8. end += mysql_real_escape_string(MyData, end,"What's this",11);
9. *end++ = '\'';
10. *end++ = ',';
11. *end++ = '\'';
12. end += mysql_real_escape_string(MyData, end,"binary data: \4\r\n",16);
13. *end++ = '\'';
14. *end++ = ')'; 15. if (mysql_real_query(MyData,query,(unsigned int) (end - query)))
16. {
17. fprintf(stderr, "Failed to insert row, Error: %s\n", mysql_error(MyData));
18. }
编译出现错误:第6行的strmov()函数不能被识别,屏蔽此行再次编译通过。
但依然没有达到将“\”作为文本字符显示在对话框上的目的。怎么解决啊