Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mysql Database connection problem

Status
Not open for further replies.

tewari68

Programmer
Jan 25, 2005
87
US
Hi,
Another question, I am using mysql database and on starting a prog I check to see whether the database is available or not, if not available then give some error message otherwise keep the database open and then close it at the end of the prog.
I am making the db connection as follows
Code:
conn = mysql_init (NULL);

 if (conn == NULL)
  {
    fprintf (stderr, "mysql_init() failed (probably out of memory)\n");
  }

  if (mysql_real_connect (
        conn,          /* pointer to connection handler */
        m_dbHost.c_str(), /* host to connect to */
        m_dbUser.c_str(), /* user name */
        m_dbPass.c_str(),  /* password */
        m_dbDatabase.c_str(),   /* database to use */
        0,             /* port (use default) */
        NULL,          /* socket (use default) */
        0)             /* flags (none) */
      == NULL)
  {
    fprintf (stderr, "mysql_real_connect() failed:\nError %u (%s)\n",
             mysql_errno (conn), mysql_error (conn));
My question is how can I pass this connection handle to another programme which executes some sql queries, the function I am calling is
Code:
// Creating LogMsg object in main()"
       LogMsg logmsg;
logmsg.updateDatabase(m_envelopTo, m_envelopFrom, m_getDateTime, m_Size, m_headerFrom, m_headerTo, m_subject, m_messageID, m_fileName, m_dispositionStr, conn);
this particular function is in logmsg.cpp.
How can I pass the db connection handle to this routine.
Thanks for any help
tewari
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top