Access to MySql with SSL from C/C++

5

I've configured MySql to use SSL and it worked well in PHP. But when i'm trying to connect to the databases with a C/C++ program, it doesn't work.

Variables :

host = "localhost"
psw = "pass"
db = "database"

Without SSL :

usr = "userNOSSL"
conn = mysql_init(NULL);
mysql_real_connect(conn, host, usr, psw, db, 0, NULL, 0);

This one worked well. i can easily retrieve data with :

query = "SELECT x FROM y"

mysql_query(conn, query);

result = mysql_store_result(conn);

num_fields = mysql_num_fields(result);

while ((row = mysql_fetch_row(result)))
{
    for(i = 0; i < num_fields; i++)
    {
        printf("%s ", row[i] ? row[i] : "NULL");
    }
    printf("\n");
}

mysql_free_result(result);

With SSL (CLIENT_SSL tag) :

usr = "userSSL"
conn = mysql_init(NULL);
mysql_real_connect(conn, host, usr, psw, db, 0, NULL, CLIENT_SSL);

The Error

Error : my "MYSQL *conn;" object is not getting parameters like "without ssl". so, it occurs an exception :

A first chance of exception at 0x0f18c274 in test_Class.exe : 0xC0000005: 
Acces violation when reading on location 0x00000048.
An unhandled exception at 0x0f18c274 in test_Class.exe : 0xC0000005: 
Acces violation when reading on location 0x00000048.

at this line :

num_fields = mysql_num_fields(result);

Same error if i do :

mysql_ssl_set(.SOMEOPTIONTHERE.)
mysql_real_connect(conn, host, usr, psw, db, 0, NULL, 0);

Thanks in advance.

c++
mysql
c
ssl
asked on Stack Overflow Mar 15, 2013 by Arn.vrn7 • edited Mar 15, 2013 by rhughes

1 Answer

0

My guess is that your local host isn't set up correctly to handle SSL. Try this: http://www.chriscalender.com/?tag=ssluserlocalhost

answered on Stack Overflow Apr 5, 2013 by chrislondon

User contributions licensed under CC BY-SA 3.0