本帖最后由 leon 于 2018-4-15 08:40 编辑
各位老大,通过mysql.udf向mysql中插入中文数据的时候总是显示乱码,请高手帮忙解答下,谢谢。
字符默认是utf8。
附件为mysql.udf,以下为插入数据代码片段:$Inputname = InputBox("用户名", "请输入将要添加的考勤用户名。", "", "", -1, 120)
Sleep(100)
$Inputpassword = InputBox("密码", "请输入考勤密码。", "", "", -1, 120)
Sleep(100)
$line = "INSERT INTO user VALUES (" & "''," & "'" & $Inputname & "', " & "'" & $Inputpassword & "')"
$connect = _MySQLConnect("attendance", "attendance", "attendance_record", "127.0.0.1", "{MySQL ODBC 3.51 Driver}", 3306)
If $connect = 0 Then
MsgBox(0, "失败", "连接数据库失败")
EndIf
If @error = 1 Then
MsgBox(0, "错误", "无法打开数据库")
ElseIf @error = 2 Then
MsgBox(0, "错误", "没有安装ODBC3.51的驱动")
EndIf
;Connect attendance_record database via mysql ODBC3.51 driver.
$Addusers = _Query($connect, $line)
If $Addusers = 0 And @error = 1 Then
MsgBox(0, "失败", "数据库连接有问题,用户添加失败。")
Else
MsgBox(0, "成功", "考勤系统成功添加" & $Inputname & "用户")
EndIf
解决方案如下:
$setchar = "set names 'gbk'"
_Query($connect, $setchar) |