mysql - mysql_options() crashing in mysqlclient.lib -
i trying use mysql_plugin_dir mysql_options(). , on doing application crashes.
here simple code crashes--
#include "stdafx.h" #include <mysql.h> #include <stdio.h> #include<conio.h> #include <stdlib.h> #include <windows.h> #include<process.h> mysql *conn; // connection mysql_res *res; // 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 create mysql instance , initialize variables within mysql *connection = mysql_init(null); // connect database 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 query 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 results return mysql_res pointer res = mysql_perform_query(conn,"select 2"); while ((row = mysql_fetch_row(res)) !=null) printf("%s\n", row[0]); /* clean database result set */ mysql_free_result(res); /* clean database link */ } void mythreadconnect(void) { struct connection_details mysqld; mysqld.server = "localhost"; // mysql database mysqld.user = "root"; // root user of mysql mysqld.password = "root"; // password of root user in mysql mysqld.database = "myfirst"; // databse pick //connect 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 exiting\n"); getch(); return 0; }
it crashes @ mysql_options(conn,mysql_plugin_dir ,path);. have searched lot can't find solution. please wrong in code. in advance.
your mistake mysql_init
. use conn = mysql_init( null );
. in case have not allocated memory conn
, try initialize. read docs mysql_init
param , return value.
Comments
Post a Comment