MySQL and C
What are the necessary headers and libraries to connect the windows version of MySQL and GCC in
cygwin?
Could you give some sample codes?
Thanks,
Michael Louie Loria
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32 [at] m.gmane.org
Re: MySQL and C
> Could you give some sample codes?
g++ -o mysql_sample `../mysql/usr/bin/mysql_config --cflags --libs` mysql_sample.c
adapt path to mysql_config
// $host = "localhost";
// $dbuser = "your-db";
// $dbpassword = "mimi";
// $database = "your-db";
//#if defined(_WIN32) || defined(_WIN64)
//#include <windows.h>
//#endif
#include <stdio.h>
#include <stdlib.h>
#include "mysql.h"
#define SELECT_QUERY "select * from marke"
int main(int argc, char **argv)
{
int count, num;
MYSQL mysql,*sock;
MYSQL_RES *result;
char qbuf[160];
mysql_init(&mysql);
if (!(sock = mysql_real_connect(&mysql,"127.0.0.1","your-db","mimi","your -db",3306,NULL,0)))
{
fprintf(stderr,"Couldn't connect to engine!\n%s\n\n",mysql_error(&mysql));
perror("");
exit(1);
}
count = 0;
num = atoi(argv[2]);
sprintf(qbuf,SELECT_QUERY);
if(mysql_query(sock,qbuf))
{
fprintf(stderr,"Query failed (%s)\n",mysql_error(sock));
exit(1);
}
if (!(result=mysql_store_result(sock)))
{
fprintf(stderr,"Couldn't get result from %s\n",
mysql_error(sock));
exit(1);
}
MYSQL_ROW row;
int num_fields = mysql_num_fields(result);
printf("num_fields: %i\n", num_fields);
while ((row = mysql_fetch_row(result)))
{
unsigned long *lengths;
lengths = mysql_fetch_lengths(result);
for(int i = 0; i < num_fields; i++)
{
printf("[%.*s] ", (int) lengths[i], row[i] ? row[i] : "NULL");
}
printf("\n");
}
mysql_close(sock);
exit(0);
return 0; /* Keep some compilers happy */
}
--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32 [at] m.gmane.org