This establishes a connection to a MySQL database engine running on the specified host. Here is its syntax:
MYSQL *mysql_real_connect(MYSQL *mysqlObject, const char *hostName, const char *userid, const char *password, const char *dbase, unsigned int port, const char *socket, unsigned long flag)
Here:
- mysqlObject represents the address of an existing MYSQL object.
- hostName is where the hostname or IP address of the host is provided. To connect to a local host, either NULL or the string localhost is provided.
- userid represents a valid MySQL login ID.
- password represents the password of the user.
- dbase represents the database name to which the connection has to be established.
- port is where either value 0 is specified or the port number for the TCP/IP connection is supplied.
- socketis where either NULL is specified or the socket or named pipe is supplied.
- flag can be used to enable certain features, such as handling expired passwords and applying compression in the client/server protocol, but its value is usually kept at 0.
The function returns a MYSQL connection handler if the connection is established; otherwise, it returns NULL.