Click here to Skip to main content
15,891,633 members
Articles / Database Development / MySQL
Article

MySQL C++ Wrapper

Rate me:
Please Sign up or sign in to vote.
2.31/5 (58 votes)
4 May 2003 260.1K   4.1K   50   61
A set of C++ classes for working with the MySQL library.

Introduction

This is a simple C++ wrapper for working with MySQL... It requires the download of MySQL headers and lib (included with MySQL server here).

Sample

A simple example on how to use:

#include "mysqlplus.h"
#include <STDIO.H>
void main()
{
   sql_connection_c connection( "database", 
           "localhost", "root", "mypassword" );
   sql_query_c query( &connection );
   sql_result_c *sql_result = 0;
   if ( !query.execute( "select * from customers" ) )
   {
      printf( "oops... didn't execute!!\n" );
      return;
   }
   sql_result = query.store();
   int n_fields = sql_result->n_fields();
   for ( int idx = 0; idx < n_fields; idx++ )
   {
      sql_field_c sql_field = sql_result->fetch_field( idx );
      printf( "field %d [%s]\n", idx, sql_field.get_name() );
   }
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Portugal Portugal
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalnewbie - error C2065: 'mysql_connect' : Pin
doctorrie19-Mar-06 12:55
doctorrie19-Mar-06 12:55 
GeneralRe: newbie - error C2065: 'mysql_connect' : Pin
fsdfdfg29-Sep-06 2:40
fsdfdfg29-Sep-06 2:40 
GeneralRe: newbie - error C2065: 'mysql_connect' : Pin
ruying19-May-08 17:03
ruying19-May-08 17:03 
GeneralRe: newbie - error C2065: 'mysql_connect' : Pin
houge15-May-10 16:44
houge15-May-10 16:44 
GeneralAdding binary data Pin
professore16-Mar-06 12:12
professore16-Mar-06 12:12 
General"oops... didn't execute!!" Pin
viperlogic13-Mar-06 10:29
viperlogic13-Mar-06 10:29 
General'sql_var_c::operator=' : must return a value Pin
kuharido30-May-05 13:38
kuharido30-May-05 13:38 
GeneralRe: 'sql_var_c::operator=' : must return a value Pin
kuharido30-May-05 13:59
kuharido30-May-05 13:59 
Ok now i fixed that , now its giving all wierd linking errors


mysqlplus.obj : error LNK2019: unresolved external symbol _mysql_query@8 referenced in function "public: int __thiscall sql_query_c::try_execute(char *)" (?try_execute@sql_query_c@@QAEHPAD@Z)
mysqlplus.obj : error LNK2019: unresolved external symbol _mysql_store_result@4 referenced in function "public: int __thiscall sql_query_c::execute(char *)" (?execute@sql_query_c@@QAEHPAD@Z)
mysqlplus.obj : error LNK2019: unresolved external symbol _mysql_insert_id@4 referenced in function "public: __int64 __thiscall sql_query_c::insert_id(void)" (?insert_id@sql_query_c@@QAE_JXZ)
mysqlplus.obj : error LNK2019: unresolved external symbol _mysql_fetch_field@4 referenced in function "public: struct st_mysql_field * __thiscall sql_query_c::fetch_field(void)" (?fetch_field@sql_query_c@@QAEPAUst_mysql_field@@XZ)
mysqlplus.obj : error LNK2019: unresolved external symbol _mysql_ping@4 referenced in function "public: int __thiscall sql_query_c::ping(void)" (?ping@sql_query_c@@QAEHXZ)
mysqlplus.obj : error LNK2019: unresolved external symbol _mysql_num_rows@4 referenced in function "public: __int64 __thiscall sql_result_c::n_rows(void)" (?n_rows@sql_result_c@@QAE_JXZ)
mysqlplus.obj : error LNK2019: unresolved external symbol _mysql_fetch_row@4 referenced in function "public: class sql_row_c __thiscall sql_result_c::fetch_row(void)" (?fetch_row@sql_result_c@@QAE?AVsql_row_c@@XZ)


GeneralRe: 'sql_var_c::operator=' : must return a value Pin
penghong2-Sep-05 1:07
penghong2-Sep-05 1:07 
Generalcompiling on newer MySQL 4.1.x Pin
mr_mark_hewitt11-Apr-05 20:53
mr_mark_hewitt11-Apr-05 20:53 
Generalwhoops now problem with insert... Pin
_kane_11-Apr-05 1:30
_kane_11-Apr-05 1:30 
Generaldoesn't work for remote host Pin
_kane_8-Apr-05 20:45
_kane_8-Apr-05 20:45 
GeneralRe: doesn't work for remote host Pin
_kane_9-Apr-05 4:05
_kane_9-Apr-05 4:05 
Generalcompile errors Pin
WJasonM13-Mar-05 13:31
WJasonM13-Mar-05 13:31 
QuestionHow to detect NULL values in query results? Pin
Member 5928316-Jan-05 8:57
Member 5928316-Jan-05 8:57 
QuestionHow do you get the name of all the database that are available Pin
benji0s10-Nov-04 9:46
sussbenji0s10-Nov-04 9:46 
AnswerRe: How do you get the name of all the database that are available Pin
mr_mark_hewitt22-Feb-06 20:29
mr_mark_hewitt22-Feb-06 20:29 
Generalcompile error Pin
Chooikw21-May-04 3:31
Chooikw21-May-04 3:31 
GeneralRe: compile error Pin
keentyjf11-Dec-04 18:15
keentyjf11-Dec-04 18:15 
Generaledate problem Pin
BlackDice22-Mar-04 7:39
BlackDice22-Mar-04 7:39 
GeneralPrior error solved--New one Pin
patjc24-Jan-04 10:50
patjc24-Jan-04 10:50 
Generalerror message Pin
patjc19-Jan-04 13:15
patjc19-Jan-04 13:15 
AnswerRe: error message Pin
A.T27-Jun-06 5:43
A.T27-Jun-06 5:43 
GeneralI voted high because.... Pin
serup5-Dec-03 3:58
serup5-Dec-03 3:58 
GeneralI voted high because.... Pin
serup5-Dec-03 3:53
serup5-Dec-03 3:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.