C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-13-2006, 09:31 AM   #1
Registered User
 
Join Date: Feb 2006
Posts: 17
Connecting to a mysql server and querying problem

Im using a library to do this. This one: libmySQL.lib

This is my code:
Code:
#include <mysql.h>
#include <stdio.h>

main() {
   MYSQL *conn;
   MYSQL_RES *res;
   MYSQL_ROW row;

   char *server = "localhost";
   char *user = "root";
   char *password = "";
   char *database = "KKI";
   
   conn = mysql_init(NULL);
   
   /* Connect to database */
   if (!mysql_real_connect(conn, server,
         user, password, database, 0, NULL, 0)) {
      fprintf(stderr, "%s\n", mysql_error(conn));
      exit(0);
   }

   /* send SQL query */
   if (mysql_query(conn, "SELECT * FROM KKI_users WHERE ID=1")) {
      fprintf(stderr, "%s\n", mysql_error(conn));
      exit(0);
   }

   res = mysql_use_result(conn);
   
   /* output fields 1 and 2 of each row */
   while ((row = mysql_fetch_row(res)) != NULL)
      printf("%s %s\n", row[1], row[2]);

   /* Release memory used to store results and close connection */
   mysql_free_result(res);
   mysql_close(conn);
}
It should work since it came from a tutorial.

This is my compiler-log:

Code:
Compiler: Default compiler
Building Makefile: "C:\test3\Makefile.win"
Bezig met uitvoeren van  make...
make.exe -f "C:\test3\Makefile.win" all
gcc.exe -c main.c -o main.o -I"C:/Dev-Cpp/include"   

In file included from C:/Dev-Cpp/include/mysql.h:68,
                 from main.c:1:
C:/Dev-Cpp/include/mysql_com.h:115: error: syntax error before "SOCKET"

C:/Dev-Cpp/include/mysql_com.h:115: warning: no semicolon at end of struct or union

C:/Dev-Cpp/include/mysql_com.h:130: error: syntax error before '}' token
C:/Dev-Cpp/include/mysql_com.h:130: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql_com.h:160: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql_com.h:161: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql_com.h:162: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql_com.h:163: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql_com.h:164: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql_com.h:165: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql_com.h:167: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql_com.h:168: error: syntax error before '*' token

In file included from main.c:1:
C:/Dev-Cpp/include/mysql.h:141: error: syntax error before "NET"
C:/Dev-Cpp/include/mysql.h:141: warning: no semicolon at end of struct or union
C:/Dev-Cpp/include/mysql.h:163: error: syntax error before '}' token
C:/Dev-Cpp/include/mysql.h:163: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql.h:176: error: syntax error before "MYSQL"
C:/Dev-Cpp/include/mysql.h:176: warning: no semicolon at end of struct or union
C:/Dev-Cpp/include/mysql.h:178: error: syntax error before '}' token
C:/Dev-Cpp/include/mysql.h:178: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql.h:183: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:184: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:185: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:186: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:188: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:189: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:190: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:192: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:193: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:194: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:195: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:196: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:197: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:198: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:199: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:201: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:201: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:201: warning: data definition has no type or storage class

C:/Dev-Cpp/include/mysql.h:209: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:209: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:210: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql.h:211: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:214: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:214: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:220: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql.h:229: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:230: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:231: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:232: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:233: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:234: error: syntax error before '*' token

C:/Dev-Cpp/include/mysql.h:236: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:238: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:239: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:240: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:241: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:242: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:244: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:245: error: syntax error before '*' token

C:/Dev-Cpp/include/mysql.h:246: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:247: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:249: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:250: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:251: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:251: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:251: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql.h:252: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:252: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:252: warning: data definition has no type or storage class

C:/Dev-Cpp/include/mysql.h:253: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:253: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:254: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql.h:255: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:255: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:255: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql.h:256: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:256: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:256: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql.h:257: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:257: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:257: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql.h:258: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:260: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:261: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:263: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:264: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:266: error: syntax error before '*' token

C:/Dev-Cpp/include/mysql.h:267: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:268: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:271: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:275: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql.h:284: error: syntax error before ')' token
C:/Dev-Cpp/include/mysql.h:285: error: syntax error before '*' token
main.c: In function `main':
main.c:5: error: `conn' undeclared (first use in this function)
main.c:5: error: (Each undeclared identifier is reported only once
main.c:5: error: for each function it appears in.)
main.c:6: error: `res' undeclared (first use in this function)

make.exe: *** [main.o] Error 1

Uitvoering voltooid
I'm using Dev-C++ 4.9.9.2. I have uploaded both mysql.h and mysql_com.h

I'm a newbie in the C++ language and im just using it to make a dll so i can get an easier access to a mysql server in VB6.
Attached Files
File Type: h mysql.h (10.4 KB, 42 views)
File Type: h mysql_com.h (8.4 KB, 25 views)
Diod is offline   Reply With Quote
Old 02-13-2006, 09:34 AM   #2
Mad
 
OnionKnight's Avatar
 
Join Date: Jan 2005
Location: Umeå, Sweden
Posts: 555
Put a #include <winsock.h> before #include <mysql.h>
OnionKnight is offline   Reply With Quote
Old 02-13-2006, 09:39 AM   #3
Registered User
 
Join Date: Feb 2006
Posts: 17
That seemed to help a bit, but now i get this:

Code:
Compiler: Default compiler
Building Makefile: "C:\test3\Makefile.win"
Bezig met uitvoeren van  make...
make.exe -f "C:\test3\Makefile.win" all
gcc.exe main.o  -o "Project 2.exe" -L"C:/Dev-Cpp/lib" ../Dev-Cpp/lib/mysql++.lib  

main.o(.text+0x4e):main.c: undefined reference to `mysql_init@4'
main.o(.text+0x93):main.c: undefined reference to `mysql_real_connect@32'
main.o(.text+0xa5):main.c: undefined reference to `mysql_error@4'
main.o(.text+0xe3):main.c: undefined reference to `mysql_query@8'
main.o(.text+0xf5):main.c: undefined reference to `mysql_error@4'

main.o(.text+0x12b):main.c: undefined reference to `mysql_use_result@4'
main.o(.text+0x13c):main.c: undefined reference to `mysql_fetch_row@4'
main.o(.text+0x179):main.c: undefined reference to `mysql_free_result@4'
main.o(.text+0x187):main.c: undefined reference to `mysql_close@4'
collect2: ld returned 1 exit status

make.exe: *** ["Project] Error 1

Uitvoering voltooid
Diod is offline   Reply With Quote
Old 02-13-2006, 09:41 AM   #4
Mad
 
OnionKnight's Avatar
 
Join Date: Jan 2005
Location: Umeå, Sweden
Posts: 555
Seems like you forgot to link libmysql.lib. I haven't used mysql++.lib but I don't think it can stand on it's own feet.
OnionKnight is offline   Reply With Quote
Old 02-13-2006, 09:48 AM   #5
Registered User
 
Join Date: Feb 2006
Posts: 17
Nope, even if i link libmysql it doenst work, not even together
Diod is offline   Reply With Quote
Old 02-13-2006, 10:05 AM   #6
Mad
 
OnionKnight's Avatar
 
Join Date: Jan 2005
Location: Umeå, Sweden
Posts: 555
I have no problem compiling it using "bcc32 mysql.c libmysql.lib". I don have Dev-Cpp installed so I can't test it with Mingw
OnionKnight is offline   Reply With Quote
Old 02-13-2006, 10:12 AM   #7
Registered User
 
Join Date: Feb 2006
Posts: 17
Is the bcc compiler for windows and if so where can i get it? (ive looked a little bit around on google but couldnt find it)
Diod is offline   Reply With Quote
Old 02-13-2006, 10:22 AM   #8
Mad
 
OnionKnight's Avatar
 
Join Date: Jan 2005
Location: Umeå, Sweden
Posts: 555
bcc32 is the Borland command-line compiler, but I don't think the compiler should matter much.
OnionKnight is offline   Reply With Quote
Old 02-13-2006, 10:33 AM   #9
Registered User
 
Join Date: Feb 2006
Posts: 17
Hmm then why doesnt it work?

EDIT: Problem solved. I opened up Microsoft Visual C++ and linked to the library, then i build it, with 1 warning (something about main, but nm) and i first got an error about libmySQL.dll, and then i went into the lib folder, got me the libmySQL.dll and copied it into the folder where my project was compiled in. Then it worked flawless

Thanks for your help mate

Last edited by Diod; 02-13-2006 at 12:15 PM. Reason: problem solved
Diod is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL libraries csonx_p C++ Programming 6 10-02-2008 02:23 AM
Query multiple servers quickly Stack Overflow Networking/Device Communication 8 05-09-2008 11:04 AM


All times are GMT -6. The time now is 08:57 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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