MYSQL *mysql_connect(MYSQL *mysql, const char *host,
        const char *user, const char *passwd)
      
Description
        This function is deprecated. Use
        mysql_real_connect() instead.
      
        mysql_connect() attempts to
        establish a connection to a MySQL database engine running on
        host.
        mysql_connect() must complete
        successfully before you can execute any of the other API
        functions, with the exception of
        mysql_get_client_info().
      
        The meanings of the parameters are the same as for the
        corresponding parameters for
        mysql_real_connect() with the
        difference that the connection parameter may be
        NULL. In this case, the C API allocates
        memory for the connection structure automatically and frees it
        when you call mysql_close(). The
        disadvantage of this approach is that you can't retrieve an
        error message if the connection fails. (To get error information
        from mysql_errno() or
        mysql_error(), you must provide
        a valid MYSQL pointer.)
      
Return Values
        Same as for
        mysql_real_connect().
      
Errors
        Same as for
        mysql_real_connect().
      


User Comments
If you need to compile old programs still using this function, you might want to add the following macro definition to your programs (possibly via the compiler's command line) so you needn't change all calls to mysql_connect() :
#define mysql_connect(m,h,u,p) mysql_real_connect((m),(h),(u),(p),NULL,0,NULL,0)
You should also make sure the MYSQL pointer is never NULL in these calls, though.
In response to the mysql_connect() macro, also make sure to call mysql_init() before using it. You didn't need to (or at least it worked) with older versions of the library. You will immediately crash if you don't.
Since mysql_connect(...) can take NULL or uninitialized MYSQL structure as first parameter, it would be better to use following code to make old programs work:
MYSQL * subst_mysql_connect(MYSQL * mysql, const char *host, const char *user, const char *passwd)
{
MYSQL * mysql_handle;
mysql_handle=mysql_init(mysql);
return mysql_real_connect(mysql_handle,host,user,passwd,NULL,0,NULL,0);
}
#define mysql_connect(m,h,u,p) subst_mysql_connect((m),(h),(u),(p))
Add your own comment.