Name
mysql_connect
Synopsis
MYSQL *mysql_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd)
Creates a connection to a MySQL database server. The first parameter
must be a predeclared MYSQL
structure. The second
parameter is the hostname or IP address of the MySQL server. If the
host is an empty string or localhost
, a connection
will be made to the MySQL server on the same machine. The final two
parameters are the username and password used to make the connection.
The password should be entered as plain text, not encrypted in any
way. The return value is the MYSQL structure passed as the first
argument, or NULL if the connection failed. (Because the structure is
contained as an argument, the only use for the return value is to
check if the connection succeeded.)
Note
This function has been deprecated in the newer releases of MySQL and
the mysql_real_connect
function should be used instead.
Example
/* Create a connection to the local MySQL server using the name "bob" and password "mypass" */ MYSQL mysql; if(!mysql_connect(&mysql, "", "bob", "mypass")) { printf("Connection error!\n"); exit(0); } /* If we've reached this point we have successfully connected to the database server. */
Get MySQL and mSQL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.