#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Austria
    Posts
    2
    Rep Power
    0

    Using MySQL API under Visual C++.NET


    I tried to use the C API (included in MySQL 4.0.12) within the following Visual C++.NET sample program.

    #include <windows.h>
    #include <stdio.h>
    #include "mysql.h"
    int main()
    {
    MYSQL conn;
    mysql_real_connect(&conn, "localhost", "root", "", NULL, 3306, NULL, 0);
    mysql_close(&conn);
    return 0;
    }

    I added the "...\MySQL\include" directory to the VC++ directories (Tools > Options > Projects), added the "...\MySQL\lib\debug\libmySQL.lb" to the project and copied the "...\MySQL\lib\debug\libmySQL.dll" into the "system32" directory.

    When trying to execute, I got an "Access Violation" error at the first call from the mysql API (doesn't matter which call it was).
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Canada
    Posts
    33
    Rep Power
    14
    Well, it's been a long time since I've used the MySQL API, but should the 4th parameter, where you have "" be the name of your database?

    Try that out, and look at the API.
    X___________
    the PhatBarren
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Austria
    Posts
    2
    Rep Power
    0

    Found Mistake, thanks anyway!


    Thanks to PhatBarren for the help, this was one of the two mistakes in the program. But the access violation is a result of the fact, that I made an instance of the MYSQL-structure instead of creating a pointer to it, which would be the correct way.

    This version of the program should work:
    #include <windows.h>
    #include <stdio.h>
    #include "mysql.h"
    int main()
    {
    MYSQL* conn;
    mysql_init(conn);
    mysql_real_connect(conn, "localhost", "root", "passme", NULL, 3306, NULL, 0);
    mysql_close(conn);
    return 0;
    }
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    2
    Rep Power
    0

    MySQL C++ SSL


    Does the mysql C API encrypt the querry and does MySQL encrypt the results? If not how do I enable it? Thanz
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    1
    Rep Power
    0
    The code doesn't run on my system... here ist my code:

    #include <windows.h>
    #include <stdio.h>
    #include <mysql.h>
    int main()
    {
    static MYSQL conn;
    mysql_init(&conn);
    mysql_real_connect(&conn, "localhost", "root", "", NULL, 3306, NULL, 0);
    mysql_close(&conn);
    return 0;
    }

    Well, it is running...

    Thanks for help!

    42
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    12
    blade42,

    You'll find your coding easier if you use MYSQL* instead of MYSQL.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/

IMN logo majestic logo threadwatch logo seochat tools logo