You can call the mysql_init() function to allocate or initialize a MYSQL object suitable for mysql_real_connect().
Syntax
MYSQL *
mysql_init(MYSQL *mysql)
Return values
An initialized MYSQL* handler is returned, or NULL is returned if there was insufficient memory to allocate a new object.
Errors
In case of insufficient memory, NULL is returned.
Notes
If mysql is a NULL pointer, the function allocates, initializes, and returns a new object. Otherwise, the object is initialized and the address of the object is returned. If mysql_init() allocates a new object, it is released when mysql_close() is called to close the connection.
In a non-multithreaded environment, mysql_init() calls mysql_library_init() automatically as necessary. However, mysql_library_init() is not thread-safe in a multithreaded environment. Therefore, mysql_init() is also not thread-safe. Before you call mysql_init(), call mysql_library_init() before generating any threads, or use a mutex to protect the mysql_library_init() call. This operation must be performed prior to any other client library call.