simple MySQL program

This is a discussion on simple MySQL program within the C++ Programming forums, part of the General Programming Boards category; hey guys i've managed to start reading from eckel's "thinking in c++", and i do feel that i begin to ...

  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,264
    >> 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, 01:27 PM
  2. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 03: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

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