Solved

#ifdef HAVE_OPENSSL is failed

Posted on 2006-11-19
5
896 Views
Last Modified: 2008-02-01
Hi Experts,
I am trying to connect MySQL through C code on SSL. I have written like:

==========================================
MYSQL *mysql_conn(connection_info *conn_info)
{
    MYSQL *connect;
    connect=mysql_init(NULL);
   if(connect==NULL)
   {
       printf("FAILED\n[-] init mysql failed:%s\n",mysql_error(connect));
       return NULL;
   }
 
  #ifdef HAVE_OPENSSL                                                                       // IFDEF CONDITION
   int in = mysql_ssl_set(connect,"certs/client-key.pem",
    "certs/client-cert.pem",
    "certs/ca-cert.pem", 0, 0);
     // printf("%d\n", in);
   #endif

   /* Connect to database */
   if(mysql_real_connect(connect,conn_info->server,conn_info->user,conn_info->password,conn_info->database,conn_info->port,NULL,0)==NULL)
   {
          printf("FAILED\n[-] Error: %s\n",mysql_error(connect));
          return NULL;
    }
    return connect;
}
================================================

It's giving error on "IFDEF CONDITION". When I remove this condition, code is working fine. However, it has suggested in tutorial that I should use that IFDEF CONDITION.
What is the problem with that condition, which approach would be better for me, I don't have have idea about that.
Please provide some solution for this problem.
0
Comment
Question by:rrahulgupta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 17976772
Since you're trying to keep your actual problem a secret (it is always nice to know what is going wrong, error message, compiler/linker/runtime error etc.), i can just guess that your compiler is very strict about C and does not like the declaration of 'in' at that place. Try

MYSQL *mysql_conn(connection_info *conn_info)
{
  #ifdef HAVE_OPENSSL                                                                      
    int in;
  #endif

    MYSQL *connect;
    connect=mysql_init(NULL);
   if(connect==NULL)
   {
       printf("FAILED\n[-] init mysql failed:%s\n",mysql_error(connect));
       return NULL;
   }
 
  #ifdef HAVE_OPENSSL                                                                       // IFDEF CONDITION
   in = mysql_ssl_set(connect,"certs/client-key.pem",
    "certs/client-cert.pem",
    "certs/ca-cert.pem", 0, 0);
     // printf("%d\n", in);
   #endif

   /* Connect to database */
   if(mysql_real_connect(connect,conn_info->server,conn_info->user,conn_info->password,conn_info->database,conn_info->port,NULL,0)==NULL)
   {
          printf("FAILED\n[-] Error: %s\n",mysql_error(connect));
          return NULL;
    }
    return connect;
}
0
 
LVL 1

Assisted Solution

by:i_mahesh
i_mahesh earned 50 total points
ID: 17978045
as jkr as suggested
one of the causes could be the due to the place where the declaration of the int variable is happening.

but it would be helpful to give out the error information you are getting (Like the error string and error code)
0
 

Author Comment

by:rrahulgupta
ID: 17979759
when i set
#define HAVE_OPENSSL 1
then it's working fine.
Does MySQL Client API not defined this macro?
0
 
LVL 86

Expert Comment

by:jkr
ID: 17980376
Yes.
0
 

Author Comment

by:rrahulgupta
ID: 17982114
thanks :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question