2014-12-16 1 views
0

mysql_options()에 MYSQL_PLUGIN_DIR을 사용하려고합니다. 그리고 이렇게하면 내 응용 프로그램이 충돌합니다. 여기 mysqlclient.lib에서 mysql_options() 충돌

그것은 mysql_options (CONN, MYSQL_PLUGIN_DIR 경로)에 충돌

#include "stdafx.h" 
#include <mysql.h> 
#include <stdio.h> 
#include<conio.h> 
#include <stdlib.h> 
#include <Windows.h> 
#include<process.h> 

MYSQL *conn;  // the connection 
MYSQL_RES *res; // the results 
MYSQL_ROW row; 
struct connection_details 
{ 
    char *server; 
    char *user; 
    char *password; 
    char *database; 
}; 

MYSQL* mysql_connection_setup(struct connection_details mysql_details) 
{ 
    // first of all create a mysql instance and initialize the variables within 
    MYSQL *connection = mysql_init(NULL); 

    // connect to the database with the details attached. 
    if (!mysql_real_connect(connection,mysql_details.server, mysql_details.user, mysql_details.password, NULL, 0, NULL, 0)) { 
     printf("Conection error : %s\n", mysql_error(connection)); 
     exit(1); 
    } 
    return connection; 
} 

MYSQL_RES* mysql_perform_query(MYSQL *connection, char *sql_query) 
{ 
    // send the query to the database 
    if (mysql_query(connection, sql_query)) 
    { 
     printf("MySQL query error : %s\n", mysql_error(connection)); 
     // exit(1); 
    } 

    return mysql_use_result(connection); 
} 
void mythread(void) 
{ 


    mysql_thread_init(); 
    // assign the results return to the MYSQL_RES pointer 
    res = mysql_perform_query(conn,"select 2"); 
    while ((row = mysql_fetch_row(res)) !=NULL) 
     printf("%s\n", row[0]); 

    /* clean up the database result set */ 
    mysql_free_result(res); 
    /* clean up the database link */ 


} 
void mythreadconnect(void) 
{ 

    struct connection_details mysqlD; 
    mysqlD.server = "localhost"; // where the mysql database is 
    mysqlD.user = "root";  // the root user of mysql 
    mysqlD.password = "root"; // the password of the root user in mysql 
    mysqlD.database = "myfirst"; // the databse to pick 

    //connect to mysql 
    conn = mysql_connection_setup(mysqlD); 





} 

int main() 
{ 
    char path[500]="C:\\Users\\abhishek\\Documents\\Visual Studio 2010\\Projects\\sampleapplication\\Debug\\"; 
    mysql_library_init(0, NULL, NULL); 
    mysql_init(conn); 
    mysql_options(conn,MYSQL_PLUGIN_DIR ,path); 
    mythreadconnect(); 
    mythread(); 
    mysql_library_end(); 
    printf("Other business in Main\n"); 
    printf("Main is exiting\n"); 
    getch(); 
    return 0; 
} 

을 crashes-- 간단한 코드;입니다 나는 많은 것을 찾았지만 해결책을 찾을 수 없다. 이 코드에서 잘못된 점을 알려주십시오. 미리 감사드립니다.

+0

'char path [] = ...'을 사용하는 것이 더 좋습니다. –

+0

나는 그것을 또한 시도했다. 방금 작동하는지 확인하기 위해 하드 코드했습니다. –

+0

나는 이것이 대답이라는 말은 아니지만 나는 단지 당신을 권합니다. –

답변

1

실수는 mysql_init입니다. 이 conn = mysql_init(NULL);을 사용하십시오. 귀하의 경우에는 conn에 대한 메모리를 할당하지 않은 상태에서 초기화를 시도하십시오. mysql_init param 및 반환 값에 대한 문서를 읽습니다.