MySQL libraries

This is a discussion on MySQL libraries within the C++ Programming forums, part of the General Programming Boards category; Hi friends... trying to connect to MySQL installed as client on my Windows PC using VS2005 ... found this code ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    MySQL libraries

    Hi friends... trying to connect to MySQL installed as client on my Windows PC using VS2005 ... found this code

    Code:
    // DB Connection Tools MySQL
    
    #include <stdio.h> 
    #define W32_LEAN_AND_MEAN 
    #include <winsock2.h> 
    #include <mysql.h> 
    
    // change these to suit your setup 
    #define TABLE_OF_INTEREST "example" 
    #define SERVER_NAME "mysql_server" 
    #define DB_USER "root" 
    #define DB_USERPASS "root" 
    #define DB_NAME "test" 
    
    // prototypes 
    void showTables(MYSQL*); 
    void showContents(MYSQL*,const char*); 
    
    int main(int argc, char* argv[]) 
    { 
    	MYSQL	 *hnd=NULL;	// mysql connection handle 
    	const char	*sinf=NULL;	// mysql server information 
    
    	hnd = mysql_init(NULL); 
    	if (NULL == mysql_real_connect(hnd,SERVER_NAME,DB_USER,DB_USERPASS,DB_NAME,0,NULL,0)) 
    	{ 
    		fprintf(stderr,"Problem encountered connecting to the &#37;s database on %s.\n",DB_NAME,SERVER_NAME); 
    	} 
    	else 
    	{ 
    		fprintf(stdout,"Connected to the %s database on %s as user '%s'.\n",DB_NAME,SERVER_NAME,DB_USER); 
    		sinf = mysql_get_server_info(hnd); 
    
    		if (sinf != NULL) 
    		{ 
    			fprintf(stdout,"Got server information: '%s'\n",sinf); 
    			showTables(hnd); 
    			showContents(hnd,TABLE_OF_INTEREST); 
    		} 
    		else 
    		{ 
    			fprintf(stderr,"Failed to retrieve the server information string.\n"); 
    		} 
    
    		mysql_close(hnd); 
    	} 
    
    	return 0; 
    } 
    
    void showTables(MYSQL *handle) 
    { 
    	MYSQL_RES	*result=NULL; // result of asking the database for a listing of its tables 
    	MYSQL_ROW	row; // one row from the result set 
    
    	result = mysql_list_tables(handle,NULL); 
    	row = mysql_fetch_row(result); 
    	fprintf(stdout,"Tables found:\n\n"); 
    	while (row) 
    	{ 
    		fprintf(stdout,"\t%s\n",row[0]); 
    		row = mysql_fetch_row(result); 
    	} 
    	mysql_free_result(result); 
    
    	fprintf(stdout,"\nEnd of tables\n"); 
    
    	return; 
    } 
    
    void showContents 
    ( 
     MYSQL	 *handle, 
     const char	*tbl 
     ) 
    { 
    	MYSQL_RES	*res=NULL; // result of querying for all rows in table 
    	MYSQL_ROW	row; // one row returned 
    	char	 sql[1024], // sql statement used to get all rows 
    		commastr[2]; // to put commas in the output 
    	int	 i,numf=0; // number of fields returned from the query 
    
    	sprintf(sql,"select * from %s",tbl); 
    	fprintf(stdout,"Using sql statement: '%s' to extract all rows from the specified table.\n",sql); 
    
    	if (!mysql_query(handle,sql)) 
    	{ 
    		res = mysql_use_result(handle); 
    		if (res) 
    		{ 
    			numf = mysql_num_fields(res); 
    			row = mysql_fetch_row(res); 
    			fprintf(stdout,"Rows returned:\n\n"); 
    			while (row) 
    			{ 
    				commastr[0]=commastr[1]=(char)NULL; 
    				for (i=0;i<numf;i++) 
    				{ 
    					if (row[i] == NULL) 
    					{ 
    						fprintf(stdout,"%sNULL",commastr); 
    					} 
    					else 
    					{ 
    						fprintf(stdout,"%s%s",commastr,row[i]); 
    					} 
    					commastr[0]=','; 
    				} 
    				fprintf(stdout,"\n"); 
    
    				row = mysql_fetch_row(res); 
    			} 
    			fprintf(stdout,"\nEnd of rows\n"); 
    
    			mysql_free_result(res); 
    		} 
    		else 
    		{ 
    			fprintf(stderr,"Failed to use the result acquired!\n"); 
    		} 
    	} 
    	else 
    	{ 
    		fprintf(stderr,"Failed to execute query. Ensure table is valid!\n"); 
    	} 
    
    	return; 
    }
    Complains about "mysql.h" not found... Where can i get these libraries, including the following?

    Code:
     #include "mysql_com.h"
     #include "mysql_time.h"
     #include "mysql_version.h"
     #include "typelib.h"
     
     #include "my_list.h"

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Did you put them somewhere when you installed MySQL? If not, are they somewhere in the MySQL folder (look for something called "include", maybe)?

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by tabstop View Post
    Did you put them somewhere when you installed MySQL? If not, are they somewhere in the MySQL folder (look for something called "include", maybe)?
    bin, docs, & share are the only folders on MySQL folder

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Erm. Nothing in share? Do you have the lib file mysql.lib or libmysql.a or something similar? (Without that, you're definitely in trouble.)

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by tabstop View Post
    Erm. Nothing in share? Do you have the lib file mysql.lib or libmysql.a or something similar? (Without that, you're definitely in trouble.)
    nope, none of those ... nothing on share ...

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,793
    Never used MySQL but... Did you just install the MySQL database? There are usually separate installation types available for a lot of these database software apps. Someone who just want the database will install the database part. Someone who wants to code and write programs for that may also need to run some kind of developer installation package as well so they'll get the libraries and headers etc...
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by hk_mp5kpdw View Post
    Never used MySQL but... Did you just install the MySQL database? There are usually separate installation types available for a lot of these database software apps. Someone who just want the database will install the database part. Someone who wants to code and write programs for that may also need to run some kind of developer installation package as well so they'll get the libraries and headers etc...
    Installed Windows ZIP/Setup.EXE (x86) from here

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MySQL in C
    By eXist in forum C Programming
    Replies: 5
    Last Post: 05-13-2009, 10:26 AM
  2. MinGW thread-safe runtime libraries
    By Mario F. in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2006, 08:15 AM
  3. Get data from mysql and use in a system.
    By smaakage in forum Tech Board
    Replies: 3
    Last Post: 10-04-2005, 12:03 PM
  4. Mysql
    By NewCodeGenerato in forum C++ Programming
    Replies: 1
    Last Post: 10-27-2003, 12:49 PM
  5. how to reach MySQL??
    By mergoktas in forum C Programming
    Replies: 2
    Last Post: 09-28-2003, 10:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21