471,570 Members | 965 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

C++ and MySQL

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
Jul 19 '05 #1
4 6670
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.
"Ben" <mi******@hotmail.com> wrote in message
news:3b**************************@posting.google.c om...
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

Jul 19 '05 #2
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;
}
----------------------------------------------------------------------------
---------------------


"Ben" <mi******@hotmail.com> wrote in message
news:3b**************************@posting.google.c om...
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

Jul 19 '05 #3
"Ben" <mi******@hotmail.com> wrote in message
news:3b**************************@posting.google.c om...
[...]
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

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003
Jul 19 '05 #4
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.

--
Stéphane Richard
"Ada World" Webmaster
http://www.adaworld.com
"Ben" <mi******@hotmail.com> wrote in message
news:3b**************************@posting.google.c om...
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

Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by mikey | last post: by
reply views Thread by Yun Guan | last post: by
reply views Thread by Mike Chirico | last post: by
2 posts views Thread by Saqib Ali | last post: by
2 posts views Thread by trihanhcie | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.