Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use ADO to connect to mysql

Shulou Source: shulou.com Published: 2022-05-31 20:46:31 09月25日 Update

This article introduces you how to use ADO to connect to mysql, the content is very detailed, interested friends can refer to, hope to be helpful to you.

First, create databases, create tables, and insert data

> show databases

> create database mydb

> user mydb

> create table mytable (id int (4) not null primary key auto_increment,name char (20) not null, sex int (4) not null default'0')

> insert into mytable (id, name, sex) values (1, 'aaa', 0)

> insert into mytable (name, sex) values ('aaa', 0)

>

2. ADO connects to mysql database

2.1 install the mysql driver

Driver name: mysql-connector-odbc-5.2.5-win32.msi

Download address: http://dev.mysql.com/downloads/connector/odbc/

2.2 configure odbc data sources

Control Panel-> system and Security-> Administrative tools-> data Source ODBC-> user DSN-> add-> MySQL ODBC 5.2 ANSI Driver

Driver and ODBC data source, must be consistent: http://blog.csdn.net/kanguolaikanguolaik/article/details/9497329

2.3 Program connects to mysql database

# include # include # include using namespace std;#import "C:\ Program Files\ Common Files\ System\ ado\ msado15.dll" no_namespace rename ("EOF", "adoEOF") int main (int argc, char * argv []) {CoInitialize (NULL); / / Connect _ ConnectionPtr pConn; pConn.CreateInstance (_ uuidof (Connection)); try {HRESULT hr = pConn- > Open ("DSN=MySQL-ODBC;server=localhost;database=mydb" "," root "," love ", adModeUnknown);} catch (_ com_error & e) {coutadoEOF) {_ variant_t vID = pRecord- > GetCollect (_ variant_t ((long) 0)); _ variant_t vName = pRecord- > GetCollect (" name "); _ variant_t vSex = pRecord- > GetCollect (" sex ") Cout

Tags: Data symbols databases programs catalogs functions projects data sources drivers configurations drivers content more systems errors settings help management good consistent Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Docker MariaDB Apple Shulou Tech Info