-
simple MySQL program
hey guys :)
i've managed to start reading from eckel's "thinking in c++", and i do feel that i begin to understand things, although linker errors are still ahead of me. untill now, i can work with strings, and iterators :D
for the moment, i'm interested in making a simple app, that connects to my local MySQL, selects a database, makes a "SELECT id,name FROM table" and prints the results.
i've tried checking dev.mysql.com, but i found no examples, and it's pretty hard for me to understand everything just from documentation.
does anyone has around, or can make up, a simple MySQL app? I've also looked for examples over google. I'm getting over 130 linker errors when I try to compile. What do i have to link, for mysql to work?
thanks,
izuael
-
>> What do i have to link, for mysql to work?
The mysql API library. This varies depending on your platform.
>> does anyone has around, or can make up, a simple MySQL app?
Here's the first thing google returned to me.
Code:
#include <stdio.h>
#include <mysql.h>
MYSQL *conn; /* pointer to connection handler */
int main ( int argc, char *argv[] )
{
conn = mysql_init ( NULL );
mysql_real_connect (
conn, /* pointer to connection handler */
"localhost", /* host to connect to */
"user_name", /* user name */
"password", /* password */
"test", /* database to use */
0, /* port (default 3306) */
NULL, /* socket or /var/lib/mysql.sock */
0 ); /* flags (none) */
mysql_close ( conn );
return 0;
}