2012-07-13 1 views
0

C++에서 MySQL 데이터베이스에 간단히 연결할 수있는 솔루션은 무엇입니까? dev.mysql.com에서 MySQL Connector를 통합하기가 어렵습니다.MySQL과 C++를 통합하는 간단한 솔루션은 무엇입니까?

예상 감사! C/C에서 MySQL을

당신이 쿼리를

로 mysql_connect를 (연결하고 실행 mysql.h 헤더 파일

세 가지 기본 API를 포함 할 필요 ++ 응용 프로그램)와 통신 할

+0

좋은 ODBC 라이브러리를 사용하십시오 ... –

+1

"단순한"연결로 정의하는 대상은 무엇입니까? – RedX

+0

간단 : 연결 -> 쿼리 -> 닫기, 내 나쁜, 나는 또한 "솔루션"전에 간단하게 언급해야합니다. 다른 사람들처럼 mySQL 커넥터를 통합하는 것은 고통입니다 http://r3dux.org/2010/11/how-to-use-mysql-connectorc-to-connect-to-a-mysql-database-in-windows/에 동의합니다. .. 내말은 왜 MySQL 설치 매뉴얼에 라이브러리 향상에 대한 언급이 없었습니까? –

답변

2

그것의 아주 간단

는 mysql_query()

mysql_close()

myspace 라이브러리 (libMysql)와 연결

0

지원 경로를 사용하여 ODBC 경로를 시도 할 수 있습니다.

몇 년 전에 나는 OTL을 사용하여 SqlServer를 인터페이스했으며 효율적으로 발견했습니다. 이제는 아무 문제없이 MySql 인터페이스를 시도했습니다 :

#include <otlv4.h> 
#include <iostream> 
using namespace std; 

int otl_x_sql_main(int argc, char **argv) 
{ 
    otl_connect db; // connect object 
    otl_connect::otl_initialize(); // initialize ODBC environment 
    try { 
     db.rlogon("DRIVER=mysql;DB=...;UID=...;PWD=..."); // connect to ODBC 

     // parametrized SELECT 
     otl_stream i(50, "SELECT product_id,model FROM product WHERE product_id >= :f<int> AND product_id < :ff<int>", db); 

     int product_id; 
     char model[100]; 

     i << 1000 << 2000; // assigning product_id range 

     // SELECT automatically executes when all input variables are assigned 
     while (!i.eof()) { 
      i >> product_id >> model; 
      cout << "product_id=" << product_id << ", model=" << model << endl; 
     } 
    } 
    catch(otl_exception& p) {  // intercept OTL exceptions 
     cerr << p.msg << endl;  // print out error message 
     cerr << p.stm_text << endl; // print out SQL that caused the error 
     cerr << p.sqlstate << endl; // print out SQLSTATE message 
     cerr << p.var_info << endl; // print out the variable that caused the error 
    } 

    return 0; 
} 
관련 문제