Thread: Problem with MYSQL

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Problem with MYSQL

    I am using the Mysql C api and the DevPack made for this. But when I am using this code, I always get an Illegal Operation message when running the program:
    Code:
    #include <windows.h>
    #include <iostream>
    #include <mysql/mysql.h>
    
    using namespace std;
    
    int main()
    {
        char *host = "sql1.badblock.com";
        char *user = "theuser";
        char *pass = "thepassword";
        char *db = "thedb";
        MYSQL_RES *result;
        MYSQL *res;
    
        MYSQL *sock;
        sock = mysql_init(0);
        if (sock) cout << "sock handle ok!" << endl;
        else {
             cout << "sock handle failed!" << endl;
             return EXIT_FAILURE;
        }
    
        if (res=mysql_real_connect(sock, host, user, pass, db, 0, NULL, 0))
             cout << "connection ok!" << endl;
        else {
             cout << "connection failed!" << endl;
             return EXIT_FAILURE;
        }
        
        mysql_query(res,"SELECT address FROM music WHERE pass=euro8");
        cout<<"Query done!";
        result=mysql_store_result(res);
        cout<<"Store result done!";
    MYSQL_FIELD *field;
    cout<<"mysql field done!";
    
    while(field = mysql_fetch_field(result))
    {
    cout<<"in while!";
        cout<<field;
    }
    cout<<"while done!";
    cin.get();
        mysql_close(sock);
    
        return EXIT_SUCCESS;
    }
    So I added some couts to see how far the program got, before illegal operation message appears. The last cout displayed is mysql field done. Any ideas?
    Last edited by maxorator; 08-25-2005 at 01:51 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. Installing MySQL
    By cerin in forum Tech Board
    Replies: 2
    Last Post: 02-18-2006, 12:30 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Problem connecting to MySQL Database?
    By MrLucky in forum C++ Programming
    Replies: 5
    Last Post: 01-30-2006, 11:30 AM