10bet网址
MySQL 8.0 C API Developer Guide
Download this Manual
PDF (US Ltr)- 1.3Mb
PDF (A4)- 1.3Mb


5.4.38 mysql_init()

MYSQL * mysql_init(MYSQL *mysql)

Description

Allocates or initializes aMYSQLobject suitable formysql_real_connect(). Ifmysqlis aNULLpointer, the function allocates, initializes, and returns a new object. Otherwise, the object is initialized and the address of the object is returned. Ifmysql_init()allocates a new object, it is freed whenmysql_close()is called to close the connection.

In a nonmultithreaded environment,mysql_init()invokesmysql_library_init()automatically as necessary. However,mysql_library_init()is not thread-safe in a multithreaded environment, and thus neither ismysql_init(). Before callingmysql_init(), either callmysql_library_init()prior to spawning any threads, or use a mutex to protect themysql_library_init()call. This should be done prior to any other client library call.

Return Values

An initializedMYSQL*handler.NULLif there was insufficient memory to allocate a new object.

Errors

In case of insufficient memory,NULLis returned.