C++ and MySQL

B

Ben

Hi

I am new to C++ and I want to know if C++ is suitable for making a GUI
application with a MySQL database. I also want to know what keywords
in books I should look for. Is DATA STRUCTURES a good one ? Do you
know any good books that talks about C++ and MySQL ?

Thank you


Ben
 
A

Ali R.

If you are planning on using MFC look up CDatabase and CRecordset. That
should get you started. There are alot of examples on writting programs
that use ODBC and SQL under MFC.

Ali R.
 
M

Moonlit

Hi,

The question is on what platform and which compiler VC++ or VC++/MFC,
X-Windows with C++. You can create gui's on all of them and can access a
mysql database to by linking to the mysql client library or use ODBC on the
windows platform, probably you can link to mysql on MS-Windows too but I
have never tried that combination..

Querying the database is quite easy too.

Here is some code from a lex/yacc (on unix) parser I wrote, to check router
configuration files for security holes, that does some lookups in a database
(it is in C since flex/bison is C based, however that shouldn't make a
difference):

So you have (mysql) init, connect,select, store, fetch and close. That's
about it.

It is real easy actually and works great.

Regards, Ron AF Greve.

----------------------------------------------------------------------------
------------------

int Refresh = 1; // This variable determines if we want to refresh. This is
set after each run
// so everytime the rules file is read the fields are
refreshed
int CheckFields( char *Field )
{
typedef struct tagFieldname_t {
char *Fieldname;
struct tagFieldname_t *Next;
}Fieldname_t;

unsigned int num_fields;
MYSQL_FIELD *fields;
MYSQL_ROW Row;
MYSQL MySQL;
MYSQL_RES *Result;
static Fieldname_t *FieldnameList;
Fieldname_t *FieldWalk = FieldnameList, *Next, **ListWalk;
int FieldCnt;
int Cnt;
int Found = 0;

if( Refresh || !FieldnameList )
{
Refresh = 0; // Reset the refresh variable
// Free list if anything in it.
while( FieldWalk )
{
Next = FieldWalk->Next;
if( FieldWalk->Fieldname ) free( FieldWalk->Fieldname );
free( FieldWalk );
FieldWalk = Next;
}

FieldnameList = NULL; // if we leave prematurly

mysql_init( &MySQL );

if( !mysql_connect( &MySQL, CoCoConf.Database, CoCoConf.Account,
CoCoConf.Password ) )
{
printf( "Couldn't connect to database account<%s> password<%s>
%s:%d\n",CoCoConf.Account, CoCoConf.Password, __FIL
E__, __LINE__ );
return 0;
}

if( mysql_select_db( &MySQL, "Asap_Auth" ) )
{
printf( "Couldn't select database in %s:%d\n", __FILE__, __LINE__ );
mysql_close( &MySQL );
return 0;
}

if( mysql_query( &MySQL, "SHOW COLUMNS FROM Routers" ) )
{
printf( "Couldn't list database fields in %s:%d\n", __FILE__,
__LINE__ );
mysql_close( &MySQL );
return 0;
}
if( !( Result = mysql_store_result( &MySQL ) ) )
{
printf( "Couldn't list database fields in %s:%d\n", __FILE__,
__LINE__ );
mysql_close( &MySQL );
return 0;
}

// Fil the list
ListWalk = &FieldnameList;
while( Row = mysql_fetch_row( Result ) )
{
if( !( *ListWalk = (Fieldname_t*)malloc( sizeof( Fieldname_t ) ) ) )
{
fprintf( stderr, "Out of memory in %s:%d\n", __FILE__, __LINE__ );
exit(1);
}
memset( *ListWalk, 0, sizeof( Fieldname_t ) );
if( !( (*ListWalk)->Fieldname = (char*)malloc( strlen( Row[0] ) +
1 ) ) )
{
fprintf( stderr, "Out of memory in %s:%d\n", __FILE__, __LINE__ );
exit(1);
}
strcpy( (*ListWalk)->Fieldname, Row[0] );
ListWalk = &(*ListWalk)->Next;
}
mysql_free_result( Result );
mysql_close( &MySQL );
}

FieldWalk = FieldnameList;

while( FieldWalk && !Found )
{
Found = !strcmp( FieldWalk->Fieldname, Field );
FieldWalk = FieldWalk->Next;
}

return Found;
}
 
D

David B. Held

Ben said:
[...]
I am new to C++ and I want to know if C++ is suitable for
making a GUI application with a MySQL database. I also
want to know what keywords in books I should look for. Is
DATA STRUCTURES a good one ? Do you know any
good books that talks about C++ and MySQL ?

If you're willing to spend a little money, definitely take a look
at C++Builder (www.borland.com).

Dave
 
S

Stephane Richard

If you are using DevC++ http://www.bloodshed.net go to your check for
updates menu options on tools. click "get list of available....." and in
the list that appears you'll see there's a MySQL DevPak you can install
which gives you everything you need to do MySQL development.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top