vfp向mysql中写入参数时,有时?通过,有时&通过,为什么?
各位高手:
我在用vfp向mysql中写入参数时,有时?通过,有时&通过,为什么?
比如:在mysql中有个表:student, 字段:name char(8).
连接字符串: nstr="Driver=MySQL ODBC 5.2w Driver;SERVER=172.168.80.49;UID=yanyang;PWD=458700;DATABASE=test;PORT=3306;charset=gbk;"
nhandle=sqlstrconnect(nstr)
ODBC连接成功后,输入:
b='100'
a=sqlexec(nhandle,"insert into student values (?b)")
?a && 通过
a=sqlexec(nhandle,"insert into student values (&b)")
?a && 通过
但是:
b=100
b1=str(100)
a=sqlexec(nhandle,"insert into student values (?b1)")
?a && 不通过
a=sqlexec(nhandle,"insert into student values (&b1)")
?a && 通过
原以为可以通用&可是:
b=DATE()
b1=LEFT(DTOC(b),8)
a=SQLEXEC(nhandle,"insert into student values (?b1)")
?a &&通过
a=SQLEXEC(nhandle,"insert into student values (&b1)")
?a &&不通过
彻底疯了! MySQL
[解决办法]
数据绑定
sqlprepare(nhandle,"insert into student values (?b)")
b = 100 sqlexec(nhandle)
b = 200 sqlexec(nhandle)
非数据绑定
b = 100 sqlexec(nhandle,"insert into student values (&b)")
b = 200 sqlexec(nhandle,"insert into student values (&b)")
此时需要给字符类型数据加上引号
b = 'abc'
sqlexec(nhandle,"insert into student values ('&b')")