一、配置MySQL ODBC
文章使用ODBC驱动:MyODBC-3.51.12-x86-win-32bit.exe
;下载地址:https://download.csdn.net/download/weixin_37914760/87663104?spm=1001.2014.3001.5501
MySQL ODBC驱动下载地址:https://dev.mysql.com/downloads/connector/odbc/
安装驱动过程中出现如下提示:This application requires Visual Studio 2019 x64 Redistributable.Please install the Redstributable thenrun this installer again.
下载Visual C++ 2015-2022安装(对应操作系统版本): https://learn.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist?view=msvc-170
配置ODBC:
PS:中文显示为乱码问题 Iinitial Statement中添加:set names gbk
二、PB连接MySQL ODBC
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False
SQLCA.DBParm = "ConnectString='DSN=ODBC名称;UID=账号;PWD=密码'"
connect using sqlca;
IF SQLCA.SQLCode <> 0 THEN
MessageBox("数据库联接失败", "错误代码:"+ SQLCA.SQLErrText)
halt
else
MessageBox("数据库联接成功", "数据库联接成功")
END IF
//执行SQL
//test-数据库名称、abc-表名
//查询表数据需要带上指定数据库名称,否则报No database selected Continue?错误
string ls_a
select a into :ls_a from test.abc using sqlca;