我正在将数据插入数据库 [英] I am inserting the data into database

查看:73
本文介绍了我正在将数据插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据插入数据库.数据中包含特殊符号,例如''.
我收到错误.我应用了adslashes方法.仍然收到错误.我该如何解决.成一对撇号.我是使用VBScript中的replace函数来完成此操作的.看起来像这样:

名称=名称.替换(" " )



SQL Server将一对撇号解释为数据库中的单个撇号.即使字符串中没有撇号,replace语句也可以正常工作.这对于Visual Basic或任何其他开发工具应该同样有效.

插入这样的字符串的SQL语法如下所示:

  INSERT 表1(columnName)
('  Merlin D''Souza')



这将在"D"和"S"之间的字段中插入单引号或撇号.


mysql_real_escape_string将完成这笔命令.

 // 定义
未签名  mysql_real_escape_string(
MYSQL * mysql,//  mysql连接的指针
 char  *至,// 目标char数组的指针
常量 字符 *来自,// 源字符数组
未签名 长度// 字符数组的长度.再没有一个字节了
)



哦,顺便说一句,如果是php的话

 mysql_real_escape_string(


val,


I want to insert the data into database.The data contains special symbols like this ''.
I am getting error.I applied addslashes method.Still i am getting an error.How can i solve it.

解决方案

What you need to do is convert each single apostraphe into a pair of apostraphes. I did this using the replace function in VBScript. It looked something like this:

name = name.Replace ("'","''")



SQL Server will interpret a pair of apostraphes as a single apostraphe in the database. The replace statement works just fine even if there are no apostraphes in the string. This should work equally well for Visual Basic or any other development tool.

The SQL syntax to insert a string like this looks something like:

INSERT Table1 (columnName)
VALUES ('Merlin D''Souza')



This will insert a single quote or apostrophe into the field between the "D" and the "S".


mysql_real_escape_string will do the trcik.

//definition
unsigned long mysql_real_escape_string(
MYSQL *mysql, //pointer of mysql connection
char *to, //pointer of destination char array
const char *from, //source character array
unsigned long length//length of character array. not a single byte more
)



oh by the way, if it is php then

mysql_real_escape_string(


val,


这篇关于我正在将数据插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆