Click here to Skip to main content
15,887,135 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 259.5K   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

 
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 
I gave you a high mark, because your wrapper class was easy and fast to implement into my own project. Thanks!

There was however one problem, which I solved by setting warnings off and adding following line, to mysqlplus.cpp :
#pragma warning( disable : 4716 ) // Disable warning messages 4716.


Johnny

ps! I know you refer to MySQL homepage for download of interface, but you only need a few files, this you could have in your project, that would make your example even more professional.
GeneralI voted high because.... Pin
serup5-Dec-03 3:53
serup5-Dec-03 3:53 
GeneralCompiling Failure (error C2065: 'mysql_connect' : undeclared identifier) Pin
InTheZone16-Oct-03 6:38
InTheZone16-Oct-03 6:38 
GeneralRe: Compiling Failure (error C2065: 'mysql_connect' : undeclared identifier) Pin
serup5-Dec-03 4:00
serup5-Dec-03 4:00 
GeneralRe: Compiling Failure (error C2065: 'mysql_connect' : undeclared identifier) Pin
elha5820-Jan-05 4:21
elha5820-Jan-05 4:21 
GeneralRe: Compiling Failure (error C2065: 'mysql_connect' : undeclared identifier) Pin
mr_mark_hewitt11-Apr-05 21:00
mr_mark_hewitt11-Apr-05 21:00 
GeneralRe: Compiling Failure (error C2065: 'mysql_connect' : undeclared identifier) Pin
daunis15-Dec-05 8:47
daunis15-Dec-05 8:47 
GeneralCompilation errors Pin
P Figueredo9-Oct-03 3:45
P Figueredo9-Oct-03 3:45 
GeneralRe: Compilation errors Pin
Anthony_Yio11-Oct-04 18:41
Anthony_Yio11-Oct-04 18:41 
GeneralRe: Compilation errors Pin
RedDragCZ7-May-07 4:27
RedDragCZ7-May-07 4:27 
GeneralPointers Pin
Matt Newman5-May-03 10:44
Matt Newman5-May-03 10:44 
GeneralRe: Pointers Pin
SevenCat23-Sep-03 23:18
SevenCat23-Sep-03 23:18 
GeneralRe: Pointers Pin
Goncalo Oliveira24-Sep-03 9:53
Goncalo Oliveira24-Sep-03 9:53 
GeneralRe: Pointers Pin
lvidaguren13-May-04 7:45
lvidaguren13-May-04 7:45 

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.