compile error with mysql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Bill :
I have add include <stdlib.h> then  recompiler, I got the error msg as
follows :

root@acer:~# gcc -o addrecord $(mysql_config --cflags) addrecord.c
$(mysql_config --libs)
addrecord.c:1: error: expected '=', ',', ';', 'asm' or '__attribute__'
before '<' token
addrecord.c: In function 'main':
addrecord.c:14: error: 'MYSQL' undeclared (first use in this function)
addrecord.c:14: error: (Each undeclared identifier is reported only once
addrecord.c:14: error: for each function it appears in.)
addrecord.c:14: error: expected ';' before 'mysql'
addrecord.c:18: warning: incompatible implicit declaration of built-in
function 'printf'
addrecord.c:21: error: 'mysql' undeclared (first use in this function)
addrecord.c:21: error: 'NULL' undeclared (first use in this function)
addrecord.c:24: warning: incompatible implicit declaration of built-in
function 'exit'
addrecord.c:31: warning: format '%s' expects type 'char *', but argument 2
has type 'int'
addrecord.c:32: warning: incompatible implicit declaration of built-in
function 'exit'
addrecord.c:38: warning: format '%s' expects type 'char *', but argument 2
has type 'int'
addrecord.c:45: warning: format '%s' expects type 'char *', but argument 2
has type 'int'


it's my code :
include <stdio.h>
include <string.h>
include <mysql.h>
include <unistd.h>
include <stdlib.h>

int mysql_exec_sql(MYSQL *mysql,const char *create_definition) {
   return
mysql_real_query(mysql,create_definition,strlen(create_definition));
}

int main(int argc, char **argv)
{

  MYSQL mysql;

char record[1000];

printf("\n\n\tCopyright Aftab Jahan
Subedar\n\t\thttp://www.geocities.com/jahan.geo";);
printf("\n\t\tjahan@xxxxxxxxxxxxx
\n\t\tPhone:+88027519050\n\t\tsupport:jahan@xxxxxxxxxxxxxx\n");

if(mysql_init(&mysql)==NULL)
	{
		printf("\nFailed to initate MySQL connection");
		exit(1);
	}

/*now you can call any MySQL API function you like*/

if
(!mysql_real_connect(&mysql,"localhost","vinod","vinodpwd",NULL,0,NULL,0))
{
    printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&mysql));
    exit(1);
}

if(mysql_select_db(&mysql,"testdb" )==0)/*success*/
    printf( "Database Selected\n");
else
    printf( "Failed to connect to Database: Error: %s\n",
mysql_error(&mysql));

strmov(record,"INSERT INTO measurement
VALUES('vinod','nanjaiah','Choice',0.333,0.834,0,91.111,0.04999,'2009-09-23
10:10:11')");

if(mysql_exec_sql(&mysql,record)==0)/*success*/
    printf( "Record Added\n");
else
    printf( "Failed to add records: Error: %s\n", mysql_error(&mysql));

mysql_close(&mysql);
}


Cheers, 
vinod


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux