1 Vote Vote

C++ write and read from mysql database

Posted by topdog 224 days ago Questions| mysql database write All

I'm working on a project where we want to write to a mysql database, I've googled around and tried a few implementations but they all fail.

For example I tried this: http://markalexanderbain.suite101.com/using-a-mysql-databases-with-c-a70097

#include "StdAfx.h"
#include <iostream>
#include <my_global.h>
#include <mysql.h>
#pragma comment(lib, "libmysql")
#pragma comment(lib, "mysqlclient")
using namespace std;

MYSQL *connection, mysql;
MYSQL_RES *result;
MYSQL_ROW row;
int query_state;

int main() 
{mysql_init(&mysql);
//connection = mysql_real_connect(&mysql,"host","user","password","database",0,0,0);
connection = mysql_real_connect(&mysql,"localhost","bainm","not_telling","cpp_data",0,0,0);
if (connection == NULL) 
cout << mysql_error(&mysql) << endl;
return 1;
}

It compiles and generates an exe file, but it closes every time I try to run it, I've added a cin.get at the end so it wouldn't close.

But the program still closes and Visual Studio 2010 gives me the following error message: The program '[32856] mysql test.exe: Native' has exited with code -1073741515 (0xc0000135).

The only thing that is common in all these implementations is the Include files and the #pragma comment(lib, "libmysql") and #pragma comment(lib, "mysqlclient") I'm using these files which are included with mysql ga 5.5.16 32 bit.

So I'm looking for a way to write to a mysql database, if any one knows how to fix this to make it work or knows another way with a tutorial please let me know.

Originally asked by: gijs007 on Stack Overflow

Discuss Bury


Who Voted for this Question