A connection to a MySQL database engine

Last Updated On Thursday 26th Aug 2021
  • MySQL is one of the most popular database management systems.
  • Storing data in a database is a very important task in any application

mysql_real_connect()

	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
)
	
  • 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.

  • socket is 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.