By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,275 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,275 IT Pros & Developers. It's quick & easy.

C++ and MySQL

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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.