Thread: simple MySQL program

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    29

    Question 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

    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

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    >> 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;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 02:42 PM
  3. simple silly program
    By verbity in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 06:06 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM