CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Jan 2024
    Posts
    15

    trying to get Database Programming with C/C++, by Manoj Debnath July 11, 2016

    trying to get Database Programming with C/C++, by Manoj Debnath July 11, 2016, to work, but having issues with getting basic part to run. db_conn is not zero, and db_conn->host results in Access to field 'host' results in a dereference of a null pointer.

    Code:
    CBankTransaction::CBankTransaction(const std::string HOST, const std::string USER,
                                       const std::string PASSWORD,
                                       const std::string DATABASE)
    {
        db_conn = mysql_init(NULL);
        if(db_conn)
        {
            db_conn = mysql_real_connect(db_conn, HOST.c_str(), USER.c_str(),
                                     PASSWORD.c_str(), DATABASE.c_str(), 0, NULL, 0);
            std::cout << "1: if(!db_conn) \n";
        }
        else
        {
            std::cout << "1: else \n";
            std::cout <<"db_conn->host = " << db_conn->host << '\n';
        }
    
        if(!db_conn)
        {
            std::cout << "2: if(!db_conn) \n";
            std::cout <<"db_conn->host = " << db_conn->host << '\n';
        }
        else
        {
            std::cout << "2: else \n";
            std::cout <<"db_conn->host = " << db_conn->host << '\n';
        }
    
    }
    both:
    Code:
    db_conn = mysql_init(NULL);
        if(!db_conn)
    and

    Code:
    db_conn = mysql_init(NULL);
        if(db_conn)
    result in trying to access a null pointer.
    is mysql server suppose to be started from outside of program?
    is there suppose to be a folder made somewhere, before program is run?
    something i am missing that was stated on https://www.codeguru.com/database/da...ming-with-c-c/ ?
    Last edited by VictorN; January 25th, 2024 at 02:20 AM. Reason: adding the code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured