Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts

    SELECT function in visual C to extract data from mysql...

    hey
    hmm anyone got some links on using mysql with c/c++
    select function and so forth.
    cheers for any info you guys can chuck at me
    P

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tryed it once, but I could only connect when the database was on he localhost. I couldn't get it to work over the internet.
    But the Select did work.
    here's my program:
    there are still a few warnings in it (wrong conversion and stuff like that) but it works (I hope)
    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <./mysql/mysql.h>
    
    int main(void)
    {
    	MYSQL_FIELD *fld; 
        MYSQL mysql;
        MYSQL_RES *res;
        MYSQL_ROW row;
    
    	char buffer[50];
    	int numRows;
    	int i;
    
    	mysql_init(&mysql);
    	mysql_real_connect(&mysql,NULL,NULL,NULL,"maes",0,NULL,0) ;
    
    	sprintf(buffer,"select * from users");
    	mysql_real_query(&mysql,buffer,strlen(buffer)) ;
    	res = mysql_store_result(&mysql);
    	numRows = mysql_num_rows(res);
    
    	while( (row = mysql_fetch_row(res)) ){
            i = 0;
    
            for( i=0; i < mysql_num_fields(res); i++ ){
                fld = mysql_fetch_field_direct(res,i);
                printf("%10s: %s\n",fld->name,row[i]);
            }  
    
    
            printf("\n\n");
        }
    
    
    	printf("OK");
    	return 0;
    }

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    oh thanks alot man
    you got a copy of #include <./mysql/mysql.h> handy?
    cheers
    P

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    >>you got a copy of #include <./mysql/mysql.h> handy?

    they are provided with mysql.
    in your mysql directory, go to the include directory.
    copy every file to your VC inlude directory. I created a subdirectory mysql so that I keep the files that I add to VC seperate from the others (I advice you to do the same )
    something like C:\Program Files\Microsoft Visual Studio\VC98\Include\mysql

    and a header file is nothing without the library files, so you'll need them too
    Copy all the lib files (C:\mysql\lib\debug) to your VC lib directory (C:\Program Files\Microsoft Visual Studio\VC98\Lib)

    then, when you have your project open in VC, go to
    project->settings->link
    and where it says "object library modules" add "libmySQL.lib" at the end (without the quotes)
    You have to do this last step everytime you start a new project
    then OK and press the compile button. Hopefully everything will go well


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •