vb6 调用mysql_real_escape_string函数的问题!请教!
最近在研究用VB6操作mysql数据库的项目,基本的操作功能已经完成。就是发现一个问题,若SQL语句中包含了C(C++)中的转义字符(例如:\t\n)或二进制数据时,就会出现字符丢失或乱码的情况,百度了很多资料,问题出在mysql_real_escape_string的上面,但实际使用这个函数时一直出错,还没有错误提示,VB6直接崩溃!我的引用为:
程序代码:
Public Declare Function mysql_real_escape_string Lib "libmySQL" (ByVal lMysql As Long, _ ByRef lTo As String, _ ByVal lFrom As String, _ ByVal lLength As Long) As Long
mysql源码中对该函数的定义如下:
程序代码:
/* Add escape characters to a string (blob?) to make it suitable for a insert to should at least have place for length*2+1 chars Returns the length of the to string */ ulong STDCALL mysql_escape_string(char *to,const char *from,ulong length) { return (uint) escape_string_for_mysql(default_charset_info, to, 0, from, length); } ulong STDCALL mysql_real_escape_string(MYSQL *mysql, char *to,const char *from, ulong length) { if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) return (uint) escape_quotes_for_mysql(mysql->charset, to, 0, from, length); return (uint) escape_string_for_mysql(mysql->charset, to, 0, from, length); }
大家帮忙看看,在VB6中怎么调用mysql_real_escape_string函数呢?万分感谢!