The following article describes how to use the C ++ library to connect to MySQL, Oracle, and ms SQL databases, A few days ago, I found SQLAPI ++ on an Internet with good reputation. It was a big surprise that I could access multiple SQL databases (Oracle) (large website database platform ).
SQLServer, DB2, Sybase, Informix, InterBase, SQLBase, MySQL (the best combination with PHP), PostgreSQL) C ++ library. SQLAPI ++ directly calls the DBMS of the local target database management system). Unlike ADO, the APIs use the OLEDBand/orODBC Middle Layer ).
The SQLAPI ++ Library plays the role of middleware for indirect and convenient access to the database, which is why SQLAPI ++ is the fastest way to access the database. You do not need to install or configure the OLEDBand/orODBC driver when developing and publishing your applications.
SQLAPI supports MicrosoftVisualC ++, BorlandC ++ Builder, and GunProjectCandC ++ Compiler.
The sample code is as follows:
- #include<stdio.h> //forprintf
- #include<SQLAPI.h>//mainSQLAPI++header
- intmain(intargc,char*argv[])
- {
- SAConnectioncon;
Connect to MySQL Data Objects
- SACommandcmd(
- &con,
- "Selectfid,fvarchar20fromtest_tbl");
Command object, which contains a query statement. // you can modify it as needed during testing.
- try
- {
Connect to database
In this routine, the database is connected to the Oracle (large website database platform) database,
Of course, it can also connect to Sybase, Informix, DB2
- // SQLServer, InterBase, SQLBaseandODBC
- Con. Connect ("test", "tester", "tester", SA_Oracle (large website database platform) _ Client );
Execute the query statement
- cmd.Execute();
Display query results
- while(cmd.FetchNext())
- {
- printf("Rowfetched:fid=%ld,fvarchar20='%s' ",
- cmd.Field("fid").asLong(),
- (constchar*)cmd.Field("fvarchar20").asString());
- }
Submit current transaction
- con.Commit();
- printf("Rowsselected! ");
- }
- catch(SAException&x)
- {
Exception Handling
- try
- {
Exit current transaction
- con.Rollback();
- }
- catch(SAException&)
- {
- }
Show error message
- printf("%s ",(constchar*)x.ErrText());
- }
- return0;
- }
The official website of SQLAPI ++ is www.sqlapi.com. It provides an evaluation version for the customer to test. Unfortunately, after the database file of the evaluated version is successfully connected to the MySQL database, a MessageBox dialog box will pop up. When I tested it, I got bored and cracked it. If necessary, I could download www.szsmart.net from my personal website, but only provided the cracked version of BCB.