Your topics are featured within relevant feeds We intelligently match your questions and connect you with 5 likely answerers who will be alerted to help. I'm using WinXP PRO and i would like to insert data from c code to mysql database. I installedDEV-C 4.9.7.0 version, devpack 5.0.5, and mysql5.1 server. Icreate the libmysql.a file with reimp and dlltool, and sopy to devcpp/lib directory. Tone tone cook it up download. Dev c++ change current line color.
![Dev c mysql.h youtube Dev c mysql.h youtube](/uploads/1/2/6/6/126641227/918650801.jpg)
![C++ C++](/uploads/1/2/6/6/126641227/629344144.jpg)
C++ Mysql Connection
Mysql.cpp
/* |
* Example to connect to MariaDB(MySQL) |
*/ |
#include<iostream> |
#include<mysql/mysql.h>// require libmysqlclient-dev |
#include<string> |
usingnamespacestd; |
/* |
* [CLASS] Process |
*/ |
classProc |
{ |
constchar* MY_HOSTNAME; |
constchar* MY_DATABASE; |
constchar* MY_USERNAME; |
constchar* MY_PASSWORD; |
constchar* MY_SOCKET; |
enum { |
MY_PORT_NO = 3306, |
MY_OPT = 0 |
}; |
MYSQL *conn; |
MYSQL_RES *res; |
MYSQL_ROW row; |
public: |
Proc(); // Constructor |
boolexecMain(); // Main Process |
}; |
/* |
* Proc - Constructor |
*/ |
Proc::Proc() |
{ |
// Initialize constants |
MY_HOSTNAME = 'localhost'; |
MY_DATABASE = 'mysql'; |
MY_USERNAME = 'root'; |
MY_PASSWORD = '7621mizuiko3701'; |
MY_SOCKET = NULL; |
} |
/* |
* Main Process |
*/ |
boolProc::execMain() |
{ |
try { |
// Format a MySQL object |
conn = mysql_init(NULL); |
// Establish a MySQL connection |
if (!mysql_real_connect( |
conn, |
MY_HOSTNAME, MY_USERNAME, |
MY_PASSWORD, MY_DATABASE, |
MY_PORT_NO, MY_SOCKET, MY_OPT)) { |
cerr << mysql_error(conn) << endl; |
returnfalse; |
} |
// Execute a sql statement |
if (mysql_query(conn, 'SHOW TABLES')) { |
cerr << mysql_error(conn) << endl; |
returnfalse; |
} |
// Get a result set |
res = mysql_use_result(conn); |
// Fetch a result set |
cout << '* MySQL - SHOW TABLES in `' |
<< MY_DATABASE << '`' << endl; |
while ((row = mysql_fetch_row(res)) != NULL) |
cout << row[0] << endl; |
// Release memories |
mysql_free_result(res); |
// Close a MySQL connection |
mysql_close(conn); |
} catch (char *e) { |
cerr << '[EXCEPTION] ' << e << endl; |
returnfalse; |
} |
returntrue; |
} |
/* |
* Execution |
*/ |
intmain(){ |
try { |
Proc objMain; |
bool bRet = objMain.execMain(); |
if (!bRet) cout << 'ERROR!' << endl; |
} catch (char *e) { |
cerr << '[EXCEPTION] ' << e << endl; |
return1; |
} |
return0; |
} |
commented Feb 3, 2017
Mysql H Command
isn't libmysqlclient-dev and the associated <mysql/mysql.h a C rather than C++ library?Ref: https://dev.mysql.com/doc/refman/5.7/en/c-api-implementations.html Spectrum.net hd auto-tune. |
Mysql H U P
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment