ODBC Connection

This is a discussion on ODBC Connection within the C++ Programming forums, part of the General Programming Boards category; Ive got MySQL on my local system and would like to use C++ to connect to the database I downloaded ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    42

    ODBC Connection

    Ive got MySQL on my local system and would like to
    use C++ to connect to the database


    I downloaded an example script from mysql.com
    but it throws all sorts of errors when i compile


    Ive done


    #include <mysql.h>


    Is there a quick way i can connect to MySQL


    Ive installed MyODBC so i just need the
    code syntax to make a connection


    Anyone know


    Marky_Mark

  2. #2
    Registered User mfc2themax's Avatar
    Join Date
    Aug 2001
    Posts
    346
    #include <stdio.h>
    #include <mysql.h>
    #define host "localhost"
    #define username "db_username"
    #define password "db_password"
    #define database "db"
    MYSQL *conn;


    int main()
    {
    conn = mysql_init(NULL);

    mysql_real_connect(conn,host,username,password,dat abase,0,NULL,0);

    MYSQL_RES *res_set;
    MYSQL_ROW row;
    unsigned int i;


    mysql_query(conn,"SELECT * FROM users WHERE userid=1");

    res_set = mysql_store_result(conn);

    unsigned int numrows = mysql_num_rows(res_set);

    while ((row = mysql_fetch_row(res_set)) != NULL)
    {

    for (i=0; i<mysql_num_fields(res_set); i++)
    {
    ():
    printf("%s\n",row[i] != NULL ? row[i] : "NULL");
    }
    }

    mysql_close(conn);
    return 0;
    }
    mfc2themax-Creator of all that is.

  3. #3
    Registered User mfc2themax's Avatar
    Join Date
    Aug 2001
    Posts
    346
    also make sure you download and compile the proper library files.
    mfc2themax-Creator of all that is.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    42
    Thanks


    Marky_Mark
    Last edited by Marky_Mark; 10-30-2001 at 03:46 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ODBC DSN-less connection
    By esaptonor in forum Windows Programming
    Replies: 8
    Last Post: 06-15-2007, 12:09 AM
  2. ODBC Connection
    By StephanC in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 02:08 AM
  3. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 05:25 AM
  4. ODBC connection not using MFC
    By knutso in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2003, 07:39 AM
  5. ODBC connection
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 09-07-2001, 09:29 AM

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