Connect to MySQL using the C ++ Library

Source: Internet
Author: User

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:

 
 
  1. #include<stdio.h> //forprintf  
  2. #include<SQLAPI.h>//mainSQLAPI++header  
  3. intmain(intargc,char*argv[])  
  4. {  
  5. SAConnectioncon; 

Connect to MySQL Data Objects

 
 
  1. SACommandcmd(  
  2. &con,  
  3. "Selectfid,fvarchar20fromtest_tbl");  

Command object, which contains a query statement. // you can modify it as needed during testing.

 
 
  1. try  
  2. {  


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

 
 
  1. // SQLServer, InterBase, SQLBaseandODBC
  2. Con. Connect ("test", "tester", "tester", SA_Oracle (large website database platform) _ Client );


Execute the query statement

 
 
  1. cmd.Execute(); 

Display query results

 
 
  1. while(cmd.FetchNext())  
  2. {  
  3. printf("Rowfetched:fid=%ld,fvarchar20='%s' ",  
  4. cmd.Field("fid").asLong(),  
  5. (constchar*)cmd.Field("fvarchar20").asString());  

Submit current transaction

 
 
  1. con.Commit();  
  2. printf("Rowsselected! ");  
  3. }  
  4. catch(SAException&x)  

Exception Handling

 
 
  1. try  

Exit current transaction

 
 
  1. con.Rollback();  
  2. }  
  3. catch(SAException&)  
  4. {  

Show error message

 
 
  1. printf("%s ",(constchar*)x.ErrText());  
  2. }  
  3. return0;  
  4. }  

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.