mysql_real_connect() - mysql/mysql.h
mysql_real_connect() attempts to
establish a connection to a MySQL database engine running on
host.
mysql_real_connect() must
complete successfully before you can execute any other API
functions that require a valid MYSQL
connection handle structure.mysql_real_connect()mysql_real_connect()hostmysql_real_connect()mysql_real_connect()MYSQLThe parameters are specified as follows:For the first parameter, specify the address of an existing
MYSQL structure. Before calling
mysql_real_connect(), call
mysql_init() to initialize
the MYSQL structure. You can change a lot
of connect options with the
mysql_options() call. See
Section 25.8.7.50, “mysql_options()”.
The value of host may be either a host
name or an IP address. If host is
NULL or the string
"localhost", a connection to the local
host is assumed. For Windows, the client connects using a
shared-memory connection, if the server has shared-memory
connections enabled. Otherwise, TCP/IP is used. For Unix,
the client connects using a Unix socket file. For local
connections, you can also influence the type of connection
to use with the MYSQL_OPT_PROTOCOL or
MYSQL_OPT_NAMED_PIPE options to
mysql_options(). The type of
connection must be supported by the server. For a
host value of "." on
Windows, the client connects using a named pipe, if the
server has named-pipe connections enabled. If named-pipe
connections are not enabled, an error occurs.
The user parameter contains the user's
MySQL login ID. If user is
NULL or the empty string
"", the current user is assumed. Under
Unix, this is the current login name. Under Windows ODBC,
the current user name must be specified explicitly. See the
Connector/ODBC section of Chapter 25, Connectors and APIs.
The passwd parameter contains the
password for user. If
passwd is NULL, only
entries in the user table for the user
that have a blank (empty) password field are checked for a
match. This enables the database administrator to set up the
MySQL privilege system in such a way that users get
different privileges depending on whether they have
specified a password.
Note
Do not attempt to encrypt the password before calling
mysql_real_connect();
password encryption is handled automatically by the client
API.
The user and passwd
parameters use whatever character set has been configured
for the MYSQL object. By default, this is
latin1, but can be changed by calling
mysql_options(mysql,
MYSQL_SET_CHARSET_NAME,
"charset_name") prior
to connecting.
db is the database name. If
db is not NULL, the
connection sets the default database to this value.
If port is not 0, the value is used as
the port number for the TCP/IP connection. Note that the
host parameter determines the type of the
connection.
If unix_socket is not
NULL, the string specifies the socket or
named pipe to use. Note that the host
parameter determines the type of the connection.
The value of client_flag is usually 0,
but can be set to a combination of the following flags to
enable certain features.
Flag NameFlag DescriptionCAN_HANDLE_EXPIRED_PASSWORDSThe client can handle expired passwords. For more information, see
Section 7.3.7, “Password Expiration and Sandbox Mode”.CLIENT_COMPRESSUse compression in the client/server protocol.CLIENT_FOUND_ROWSReturn the number of found (matched) rows, not the number of changed
rows.CLIENT_IGNORE_SIGPIPEPrevents the client library from installing a SIGPIPE
signal handler. This can be used to avoid conflicts
with a handler that the application has already
installed.CLIENT_IGNORE_SPACEPermit spaces after function names. Makes all functions names reserved
words.CLIENT_INTERACTIVEPermit interactive_timeout seconds of
inactivity (rather than
wait_timeout
seconds) before closing the connection. The client's
session
wait_timeout
variable is set to the value of the session
interactive_timeout
variable.CLIENT_LOCAL_FILESEnable LOAD DATA
LOCAL handling.CLIENT_MULTI_RESULTSTell the server that the client can handle multiple result sets from
multiple-statement executions or stored procedures.
This flag is automatically enabled if
CLIENT_MULTI_STATEMENTS is
enabled. See the note following this table for more
information about this flag.CLIENT_MULTI_STATEMENTSTell the server that the client may send multiple statements in a single
string (separated by ;
characters). If this flag is not set,
multiple-statement execution is disabled. See the
note following this table for more information about
this flag.CLIENT_NO_SCHEMADo not permit db_name.tbl_name.col_name
syntax. This is for ODBC. It causes the parser to
generate an error if you use that syntax, which is
useful for trapping bugs in some ODBC programs.CLIENT_ODBCUnused.CLIENT_SSLUse SSL (encrypted protocol). Do not set this option within an
application program; it is set internally in the
client library. Instead, use
mysql_ssl_set()
before calling
mysql_real_connect().CLIENT_REMEMBER_OPTIONSRemember options specified by calls to
mysql_options().
Without this option, if
mysql_real_connect()
fails, you must repeat the
mysql_options()
calls before trying to connect again. With this
option, the
mysql_options()
calls need not be repeated.For the first parameter, specify the address of an existing
MYSQL structure. Before calling
mysql_real_connect(), call
mysql_init() to initialize
the MYSQL structure. You can change a lot
of connect options with the
mysql_options() call. See
Section 25.8.7.50, “mysql_options()”.
The value of host may be either a host
name or an IP address. If host is
NULL or the string
"localhost", a connection to the local
host is assumed. For Windows, the client connects using a
shared-memory connection, if the server has shared-memory
connections enabled. Otherwise, TCP/IP is used. For Unix,
the client connects using a Unix socket file. For local
connections, you can also influence the type of connection
to use with the MYSQL_OPT_PROTOCOL or
MYSQL_OPT_NAMED_PIPE options to
mysql_options(). The type of
connection must be supported by the server. For a
host value of "." on
Windows, the client connects using a named pipe, if the
server has named-pipe connections enabled. If named-pipe
connections are not enabled, an error occurs.
The user parameter contains the user's
MySQL login ID. If user is
NULL or the empty string
"", the current user is assumed. Under
Unix, this is the current login name. Under Windows ODBC,
the current user name must be specified explicitly. See the
Connector/ODBC section of Chapter 25, Connectors and APIs.
The passwd parameter contains the
password for user. If
passwd is NULL, only
entries in the user table for the user
that have a blank (empty) password field are checked for a
match. This enables the database administrator to set up the
MySQL privilege system in such a way that users get
different privileges depending on whether they have
specified a password.
Note
Do not attempt to encrypt the password before calling
mysql_real_connect();
password encryption is handled automatically by the client
API.
The user and passwd
parameters use whatever character set has been configured
for the MYSQL object. By default, this is
latin1, but can be changed by calling
mysql_options(mysql,
MYSQL_SET_CHARSET_NAME,
"charset_name") prior
to connecting.
db is the database name. If
db is not NULL, the
connection sets the default database to this value.
If port is not 0, the value is used as
the port number for the TCP/IP connection. Note that the
host parameter determines the type of the
connection.
If unix_socket is not
NULL, the string specifies the socket or
named pipe to use. Note that the host
parameter determines the type of the connection.
The value of client_flag is usually 0,
but can be set to a combination of the following flags to
enable certain features.
Flag NameFlag DescriptionCAN_HANDLE_EXPIRED_PASSWORDSThe client can handle expired passwords. For more information, see
Section 7.3.7, “Password Expiration and Sandbox Mode”.CLIENT_COMPRESSUse compression in the client/server protocol.CLIENT_FOUND_ROWSReturn the number of found (matched) rows, not the number of changed
rows.CLIENT_IGNORE_SIGPIPEPrevents the client library from installing a SIGPIPE
signal handler. This can be used to avoid conflicts
with a handler that the application has already
installed.CLIENT_IGNORE_SPACEPermit spaces after function names. Makes all functions names reserved
words.CLIENT_INTERACTIVEPermit interactive_timeout seconds of
inactivity (rather than
wait_timeout
seconds) before closing the connection. The client's
session
wait_timeout
variable is set to the value of the session
interactive_timeout
variable.CLIENT_LOCAL_FILESEnable LOAD DATA
LOCAL handling.CLIENT_MULTI_RESULTSTell the server that the client can handle multiple result sets from
multiple-statement executions or stored procedures.
This flag is automatically enabled if
CLIENT_MULTI_STATEMENTS is
enabled. See the note following this table for more
information about this flag.CLIENT_MULTI_STATEMENTSTell the server that the client may send multiple statements in a single
string (separated by ;
characters). If this flag is not set,
multiple-statement execution is disabled. See the
note following this table for more information about
this flag.CLIENT_NO_SCHEMADo not permit db_name.tbl_name.col_name
syntax. This is for ODBC. It causes the parser to
generate an error if you use that syntax, which is
useful for trapping bugs in some ODBC programs.CLIENT_ODBCUnused.CLIENT_SSLUse SSL (encrypted protocol). Do not set this option within an
application program; it is set internally in the
client library. Instead, use
mysql_ssl_set()
before calling
mysql_real_connect().CLIENT_REMEMBER_OPTIONSRemember options specified by calls to
mysql_options().
Without this option, if
mysql_real_connect()
fails, you must repeat the
mysql_options()
calls before trying to connect again. With this
option, the
mysql_options()
calls need not be repeated.For the first parameter, specify the address of an existing
MYSQL structure. Before calling
mysql_real_connect(), call
mysql_init() to initialize
the MYSQL structure. You can change a lot
of connect options with the
mysql_options() call. See
Section 25.8.7.50, “mysql_options()”.For the first parameter, specify the address of an existing
MYSQL structure. Before calling
mysql_real_connect(), call
mysql_init() to initialize
the MYSQL structure. You can change a lot
of connect options with the
mysql_options() call. See
Section 25.8.7.50, “mysql_options()”.MYSQLmysql_real_connect()mysql_real_connect()mysql_init()mysql_init()MYSQLmysql_options()mysql_options()Section 25.8.7.50, “mysql_options()”The value of host may be either a host
name or an IP address. If host is
NULL or the string
"localhost", a connection to the local
host is assumed. For Windows, the client connects using a
shared-memory connection, if the server has shared-memory
connections enabled. Otherwise, TCP/IP is used. For Unix,
the client connects using a Unix socket file. For local
connections, you can also influence the type of connection
to use with the MYSQL_OPT_PROTOCOL or
MYSQL_OPT_NAMED_PIPE options to
mysql_options(). The type of
connection must be supported by the server. For a
host value of "." on
Windows, the client connects using a named pipe, if the
server has named-pipe connections enabled. If named-pipe
connections are not enabled, an error occurs.The value of host may be either a host
name or an IP address. If host is
NULL or the string
"localhost", a connection to the local
host is assumed. For Windows, the client connects using a
shared-memory connection, if the server has shared-memory
connections enabled. Otherwise, TCP/IP is used. For Unix,
the client connects using a Unix socket file. For local
connections, you can also influence the type of connection
to use with the MYSQL_OPT_PROTOCOL or
MYSQL_OPT_NAMED_PIPE options to
mysql_options(). The type of
connection must be supported by the server. For a
host value of "." on
Windows, the client connects using a named pipe, if the
server has named-pipe connections enabled. If named-pipe
connections are not enabled, an error occurs.hosthostNULL"localhost"MYSQL_OPT_PROTOCOLMYSQL_OPT_NAMED_PIPEmysql_options()mysql_options()host"."The user parameter contains the user's
MySQL login ID. If user is
NULL or the empty string
"", the current user is assumed. Under
Unix, this is the current login name. Under Windows ODBC,
the current user name must be specified explicitly. See the
Connector/ODBC section of Chapter 25, Connectors and APIs.The user parameter contains the user's
MySQL login ID. If user is
NULL or the empty string
"", the current user is assumed. Under
Unix, this is the current login name. Under Windows ODBC,
the current user name must be specified explicitly. See the
Connector/ODBC section of Chapter 25, Connectors and APIs.useruserNULL""Chapter 25, Connectors and APIsConnectors and APIsThe passwd parameter contains the
password for user. If
passwd is NULL, only
entries in the user table for the user
that have a blank (empty) password field are checked for a
match. This enables the database administrator to set up the
MySQL privilege system in such a way that users get
different privileges depending on whether they have
specified a password.
Note
Do not attempt to encrypt the password before calling
mysql_real_connect();
password encryption is handled automatically by the client
API.The passwd parameter contains the
password for user. If
passwd is NULL, only
entries in the user table for the user
that have a blank (empty) password field are checked for a
match. This enables the database administrator to set up the
MySQL privilege system in such a way that users get
different privileges depending on whether they have
specified a password.passwduserpasswdNULLuserNote
Do not attempt to encrypt the password before calling
mysql_real_connect();
password encryption is handled automatically by the client
API.NoteDo not attempt to encrypt the password before calling
mysql_real_connect();
password encryption is handled automatically by the client
API.mysql_real_connect()mysql_real_connect()The user and passwd
parameters use whatever character set has been configured
for the MYSQL object. By default, this is
latin1, but can be changed by calling
mysql_options(mysql,
MYSQL_SET_CHARSET_NAME,
"charset_name") prior
to connecting.The user and passwd
parameters use whatever character set has been configured
for the MYSQL object. By default, this is
latin1, but can be changed by calling
mysql_options(mysql,
MYSQL_SET_CHARSET_NAME,
"charset_name") prior
to connecting.userpasswdMYSQLlatin1mysql_options(mysql,
MYSQL_SET_CHARSET_NAME,
"charset_name")mysql_options(mysql,
MYSQL_SET_CHARSET_NAME,
"charset_name")charset_namecharset_namedb is the database name. If
db is not NULL, the
connection sets the default database to this value.db is the database name. If
db is not NULL, the
connection sets the default database to this value.dbdbNULLIf port is not 0, the value is used as
the port number for the TCP/IP connection. Note that the
host parameter determines the type of the
connection.If port is not 0, the value is used as
the port number for the TCP/IP connection. Note that the
host parameter determines the type of the
connection.porthostIf unix_socket is not
NULL, the string specifies the socket or
named pipe to use. Note that the host
parameter determines the type of the connection.If unix_socket is not
NULL, the string specifies the socket or
named pipe to use. Note that the host
parameter determines the type of the connection.unix_socketNULLhostThe value of client_flag is usually 0,
but can be set to a combination of the following flags to
enable certain features.
Flag NameFlag DescriptionCAN_HANDLE_EXPIRED_PASSWORDSThe client can handle expired passwords. For more information, see
Section 7.3.7, “Password Expiration and Sandbox Mode”.CLIENT_COMPRESSUse compression in the client/server protocol.CLIENT_FOUND_ROWSReturn the number of found (matched) rows, not the number of changed
rows.CLIENT_IGNORE_SIGPIPEPrevents the client library from installing a SIGPIPE
signal handler. This can be used to avoid conflicts
with a handler that the application has already
installed.CLIENT_IGNORE_SPACEPermit spaces after function names. Makes all functions names reserved
words.CLIENT_INTERACTIVEPermit interactive_timeout seconds of
inactivity (rather than
wait_timeout
seconds) before closing the connection. The client's
session
wait_timeout
variable is set to the value of the session
interactive_timeout
variable.CLIENT_LOCAL_FILESEnable LOAD DATA
LOCAL handling.CLIENT_MULTI_RESULTSTell the server that the client can handle multiple result sets from
multiple-statement executions or stored procedures.
This flag is automatically enabled if
CLIENT_MULTI_STATEMENTS is
enabled. See the note following this table for more
information about this flag.CLIENT_MULTI_STATEMENTSTell the server that the client may send multiple statements in a single
string (separated by ;
characters). If this flag is not set,
multiple-statement execution is disabled. See the
note following this table for more information about
this flag.CLIENT_NO_SCHEMADo not permit db_name.tbl_name.col_name
syntax. This is for ODBC. It causes the parser to
generate an error if you use that syntax, which is
useful for trapping bugs in some ODBC programs.CLIENT_ODBCUnused.CLIENT_SSLUse SSL (encrypted protocol). Do not set this option within an
application program; it is set internally in the
client library. Instead, use
mysql_ssl_set()
before calling
mysql_real_connect().CLIENT_REMEMBER_OPTIONSRemember options specified by calls to
mysql_options().
Without this option, if
mysql_real_connect()
fails, you must repeat the
mysql_options()
calls before trying to connect again. With this
option, the
mysql_options()
calls need not be repeated.The value of client_flag is usually 0,
but can be set to a combination of the following flags to
enable certain features.client_flagFlag NameFlag DescriptionCAN_HANDLE_EXPIRED_PASSWORDSThe client can handle expired passwords. For more information, see
Section 7.3.7, “Password Expiration and Sandbox Mode”.CLIENT_COMPRESSUse compression in the client/server protocol.CLIENT_FOUND_ROWSReturn the number of found (matched) rows, not the number of changed
rows.CLIENT_IGNORE_SIGPIPEPrevents the client library from installing a SIGPIPE
signal handler. This can be used to avoid conflicts
with a handler that the application has already
installed.CLIENT_IGNORE_SPACEPermit spaces after function names. Makes all functions names reserved
words.CLIENT_INTERACTIVEPermit interactive_timeout seconds of
inactivity (rather than
wait_timeout
seconds) before closing the connection. The client's
session
wait_timeout
variable is set to the value of the session
interactive_timeout
variable.CLIENT_LOCAL_FILESEnable LOAD DATA
LOCAL handling.CLIENT_MULTI_RESULTSTell the server that the client can handle multiple result sets from
multiple-statement executions or stored procedures.
This flag is automatically enabled if
CLIENT_MULTI_STATEMENTS is
enabled. See the note following this table for more
information about this flag.CLIENT_MULTI_STATEMENTSTell the server that the client may send multiple statements in a single
string (separated by ;
characters). If this flag is not set,
multiple-statement execution is disabled. See the
note following this table for more information about
this flag.CLIENT_NO_SCHEMADo not permit db_name.tbl_name.col_name
syntax. This is for ODBC. It causes the parser to
generate an error if you use that syntax, which is
useful for trapping bugs in some ODBC programs.CLIENT_ODBCUnused.CLIENT_SSLUse SSL (encrypted protocol). Do not set this option within an
application program; it is set internally in the
client library. Instead, use
mysql_ssl_set()
before calling
mysql_real_connect().CLIENT_REMEMBER_OPTIONSRemember options specified by calls to
mysql_options().
Without this option, if
mysql_real_connect()
fails, you must repeat the
mysql_options()
calls before trying to connect again. With this
option, the
mysql_options()
calls need not be repeated.Flag NameFlag DescriptionCAN_HANDLE_EXPIRED_PASSWORDSThe client can handle expired passwords. For more information, see
Section 7.3.7, “Password Expiration and Sandbox Mode”.CLIENT_COMPRESSUse compression in the client/server protocol.CLIENT_FOUND_ROWSReturn the number of found (matched) rows, not the number of changed
rows.CLIENT_IGNORE_SIGPIPEPrevents the client library from installing a SIGPIPE
signal handler. This can be used to avoid conflicts
with a handler that the application has already
installed.CLIENT_IGNORE_SPACEPermit spaces after function names. Makes all functions names reserved
words.CLIENT_INTERACTIVEPermit interactive_timeout seconds of
inactivity (rather than
wait_timeout
seconds) before closing the connection. The client's
session
wait_timeout
variable is set to the value of the session
interactive_timeout
variable.CLIENT_LOCAL_FILESEnable LOAD DATA
LOCAL handling.CLIENT_MULTI_RESULTSTell the server that the client can handle multiple result sets from
multiple-statement executions or stored procedures.
This flag is automatically enabled if
CLIENT_MULTI_STATEMENTS is
enabled. See the note following this table for more
information about this flag.CLIENT_MULTI_STATEMENTSTell the server that the client may send multiple statements in a single
string (separated by ;
characters). If this flag is not set,
multiple-statement execution is disabled. See the
note following this table for more information about
this flag.CLIENT_NO_SCHEMADo not permit db_name.tbl_name.col_name
syntax. This is for ODBC. It causes the parser to
generate an error if you use that syntax, which is
useful for trapping bugs in some ODBC programs.CLIENT_ODBCUnused.CLIENT_SSLUse SSL (encrypted protocol). Do not set this option within an
application program; it is set internally in the
client library. Instead, use
mysql_ssl_set()
before calling
mysql_real_connect().CLIENT_REMEMBER_OPTIONSRemember options specified by calls to
mysql_options().
Without this option, if
mysql_real_connect()
fails, you must repeat the
mysql_options()
calls before trying to connect again. With this
option, the
mysql_options()
calls need not be repeated.Flag NameFlag DescriptionFlag NameFlag DescriptionFlag NameFlag DescriptionCAN_HANDLE_EXPIRED_PASSWORDSThe client can handle expired passwords. For more information, see
Section 7.3.7, “Password Expiration and Sandbox Mode”.CLIENT_COMPRESSUse compression in the client/server protocol.CLIENT_FOUND_ROWSReturn the number of found (matched) rows, not the number of changed
rows.CLIENT_IGNORE_SIGPIPEPrevents the client library from installing a SIGPIPE
signal handler. This can be used to avoid conflicts
with a handler that the application has already
installed.CLIENT_IGNORE_SPACEPermit spaces after function names. Makes all functions names reserved
words.CLIENT_INTERACTIVEPermit interactive_timeout seconds of
inactivity (rather than
wait_timeout
seconds) before closing the connection. The client's
session
wait_timeout
variable is set to the value of the session
interactive_timeout
variable.CLIENT_LOCAL_FILESEnable LOAD DATA
LOCAL handling.CLIENT_MULTI_RESULTSTell the server that the client can handle multiple result sets from
multiple-statement executions or stored procedures.
This flag is automatically enabled if
CLIENT_MULTI_STATEMENTS is
enabled. See the note following this table for more
information about this flag.CLIENT_MULTI_STATEMENTSTell the server that the client may send multiple statements in a single
string (separated by ;
characters). If this flag is not set,
multiple-statement execution is disabled. See the
note following this table for more information about
this flag.CLIENT_NO_SCHEMADo not permit db_name.tbl_name.col_name
syntax. This is for ODBC. It causes the parser to
generate an error if you use that syntax, which is
useful for trapping bugs in some ODBC programs.CLIENT_ODBCUnused.CLIENT_SSLUse SSL (encrypted protocol). Do not set this option within an
application program; it is set internally in the
client library. Instead, use
mysql_ssl_set()
before calling
mysql_real_connect().CLIENT_REMEMBER_OPTIONSRemember options specified by calls to
mysql_options().
Without this option, if
mysql_real_connect()
fails, you must repeat the
mysql_options()
calls before trying to connect again. With this
option, the
mysql_options()
calls need not be repeated.CAN_HANDLE_EXPIRED_PASSWORDSThe client can handle expired passwords. For more information, see
Section 7.3.7, “Password Expiration and Sandbox Mode”.CAN_HANDLE_EXPIRED_PASSWORDSCAN_HANDLE_EXPIRED_PASSWORDSThe client can handle expired passwords. For more information, see
Section 7.3.7, “Password Expiration and Sandbox Mode”.Section 7.3.7, “Password Expiration and Sandbox Mode”CLIENT_COMPRESSUse compression in the client/server protocol.CLIENT_COMPRESSCLIENT_COMPRESSUse compression in the client/server protocol.CLIENT_FOUND_ROWSReturn the number of found (matched) rows, not the number of changed
rows.CLIENT_FOUND_ROWSCLIENT_FOUND_ROWSReturn the number of found (matched) rows, not the number of changed
rows.CLIENT_IGNORE_SIGPIPEPrevents the client library from installing a SIGPIPE
signal handler. This can be used to avoid conflicts
with a handler that the application has already
installed.CLIENT_IGNORE_SIGPIPECLIENT_IGNORE_SIGPIPEPrevents the client library from installing a SIGPIPE
signal handler. This can be used to avoid conflicts
with a handler that the application has already
installed.SIGPIPECLIENT_IGNORE_SPACEPermit spaces after function names. Makes all functions names reserved
words.CLIENT_IGNORE_SPACECLIENT_IGNORE_SPACEPermit spaces after function names. Makes all functions names reserved
words.CLIENT_INTERACTIVEPermit interactive_timeout seconds of
inactivity (rather than
wait_timeout
seconds) before closing the connection. The client's
session
wait_timeout
variable is set to the value of the session
interactive_timeout
variable.CLIENT_INTERACTIVECLIENT_INTERACTIVEPermit interactive_timeout seconds of
inactivity (rather than
wait_timeout
seconds) before closing the connection. The client's
session
wait_timeout
variable is set to the value of the session
interactive_timeout
variable.interactive_timeoutinteractive_timeoutwait_timeoutwait_timeoutwait_timeoutwait_timeoutinteractive_timeoutinteractive_timeoutCLIENT_LOCAL_FILESEnable LOAD DATA
LOCAL handling.CLIENT_LOCAL_FILESCLIENT_LOCAL_FILESEnable LOAD DATA
LOCAL handling.LOAD DATA
LOCALLOAD DATA
LOCALCLIENT_MULTI_RESULTSTell the server that the client can handle multiple result sets from
multiple-statement executions or stored procedures.
This flag is automatically enabled if
CLIENT_MULTI_STATEMENTS is
enabled. See the note following this table for more
information about this flag.CLIENT_MULTI_RESULTSCLIENT_MULTI_RESULTSTell the server that the client can handle multiple result sets from
multiple-statement executions or stored procedures.
This flag is automatically enabled if
CLIENT_MULTI_STATEMENTS is
enabled. See the note following this table for more
information about this flag.CLIENT_MULTI_STATEMENTSCLIENT_MULTI_STATEMENTSTell the server that the client may send multiple statements in a single
string (separated by ;
characters). If this flag is not set,
multiple-statement execution is disabled. See the
note following this table for more information about
this flag.CLIENT_MULTI_STATEMENTSCLIENT_MULTI_STATEMENTSTell the server that the client may send multiple statements in a single
string (separated by ;
characters). If this flag is not set,
multiple-statement execution is disabled. See the
note following this table for more information about
this flag.;CLIENT_NO_SCHEMADo not permit db_name.tbl_name.col_name
syntax. This is for ODBC. It causes the parser to
generate an error if you use that syntax, which is
useful for trapping bugs in some ODBC programs.CLIENT_NO_SCHEMACLIENT_NO_SCHEMADo not permit db_name.tbl_name.col_name
syntax. This is for ODBC. It causes the parser to
generate an error if you use that syntax, which is
useful for trapping bugs in some ODBC programs.db_name.tbl_name.col_namedb_name.tbl_name.col_nameCLIENT_ODBCUnused.CLIENT_ODBCCLIENT_ODBCUnused.CLIENT_SSLUse SSL (encrypted protocol). Do not set this option within an
application program; it is set internally in the
client library. Instead, use
mysql_ssl_set()
before calling
mysql_real_connect().CLIENT_SSLCLIENT_SSLUse SSL (encrypted protocol). Do not set this option within an
application program; it is set internally in the
client library. Instead, use
mysql_ssl_set()
before calling
mysql_real_connect().mysql_ssl_set()mysql_ssl_set()mysql_real_connect()mysql_real_connect()CLIENT_REMEMBER_OPTIONSRemember options specified by calls to
mysql_options().
Without this option, if
mysql_real_connect()
fails, you must repeat the
mysql_options()
calls before trying to connect again. With this
option, the
mysql_options()
calls need not be repeated.CLIENT_REMEMBER_OPTIONSCLIENT_REMEMBER_OPTIONSRemember options specified by calls to
mysql_options().
Without this option, if
mysql_real_connect()
fails, you must repeat the
mysql_options()
calls before trying to connect again. With this
option, the
mysql_options()
calls need not be repeated.mysql_options()mysql_options()mysql_real_connect()mysql_real_connect()mysql_options()mysql_options()mysql_options()mysql_options()If your program uses CALL
statements to execute stored procedures, the
CLIENT_MULTI_RESULTS flag must be enabled.
This is because each CALL returns
a result to indicate the call status, in addition to any result
sets that might be returned by statements executed within the
procedure. Because CALL can
return multiple results, process them using a loop that calls
mysql_next_result() to determine
whether there are more results.CALLCALLCLIENT_MULTI_RESULTSCALLCALLCALLCALLmysql_next_result()mysql_next_result()CLIENT_MULTI_RESULTS can be enabled when you
call mysql_real_connect(),
either explicitly by passing the
CLIENT_MULTI_RESULTS flag itself, or
implicitly by passing CLIENT_MULTI_STATEMENTS
(which also enables CLIENT_MULTI_RESULTS). In
MySQL 5.7, CLIENT_MULTI_RESULTS
is enabled by default.CLIENT_MULTI_RESULTSmysql_real_connect()mysql_real_connect()CLIENT_MULTI_RESULTSCLIENT_MULTI_STATEMENTSCLIENT_MULTI_RESULTSCLIENT_MULTI_RESULTSIf you enable CLIENT_MULTI_STATEMENTS or
CLIENT_MULTI_RESULTS, process the result for
every call to mysql_query() or
mysql_real_query() by using a
loop that calls
mysql_next_result() to determine
whether there are more results. For an example, see
Section 25.8.17, “C API Support for Multiple Statement Execution”.CLIENT_MULTI_STATEMENTSCLIENT_MULTI_RESULTSmysql_query()mysql_query()mysql_real_query()mysql_real_query()mysql_next_result()mysql_next_result()Section 25.8.17, “C API Support for Multiple Statement Execution”For some parameters, it is possible to have the value taken from
an option file rather than from an explicit value in the
mysql_real_connect() call. To do
this, call mysql_options() with
the MYSQL_READ_DEFAULT_FILE or
MYSQL_READ_DEFAULT_GROUP option before
calling mysql_real_connect().
Then, in the
mysql_real_connect() call,
specify the “no-value” value for each parameter to
be read from an option file:mysql_real_connect()mysql_real_connect()mysql_options()mysql_options()MYSQL_READ_DEFAULT_FILEMYSQL_READ_DEFAULT_GROUPmysql_real_connect()mysql_real_connect()mysql_real_connect()mysql_real_connect()“no-value”no-valueFor host, specify a value of
NULL or the empty string
("").
For user, specify a value of
NULL or the empty string.
For passwd, specify a value of
NULL. (For the password, a value of the
empty string in the
mysql_real_connect() call
cannot be overridden in an option file, because the empty
string indicates explicitly that the MySQL account must have
an empty password.)
For db, specify a value of
NULL or the empty string.
For port, specify a value of 0.
For unix_socket, specify a value of
NULL.For host, specify a value of
NULL or the empty string
("").
For user, specify a value of
NULL or the empty string.
For passwd, specify a value of
NULL. (For the password, a value of the
empty string in the
mysql_real_connect() call
cannot be overridden in an option file, because the empty
string indicates explicitly that the MySQL account must have
an empty password.)
For db, specify a value of
NULL or the empty string.
For port, specify a value of 0.
For unix_socket, specify a value of
NULL.For host, specify a value of
NULL or the empty string
("").For host, specify a value of
NULL or the empty string
("").hostNULL""For user, specify a value of
NULL or the empty string.For user, specify a value of
NULL or the empty string.userNULLFor passwd, specify a value of
NULL. (For the password, a value of the
empty string in the
mysql_real_connect() call
cannot be overridden in an option file, because the empty
string indicates explicitly that the MySQL account must have
an empty password.)For passwd, specify a value of
NULL. (For the password, a value of the
empty string in the
mysql_real_connect() call
cannot be overridden in an option file, because the empty
string indicates explicitly that the MySQL account must have
an empty password.)passwdNULLmysql_real_connect()mysql_real_connect()For db, specify a value of
NULL or the empty string.For db, specify a value of
NULL or the empty string.dbNULLFor port, specify a value of 0.For port, specify a value of 0.portFor unix_socket, specify a value of
NULL.For unix_socket, specify a value of
NULL.unix_socketNULLIf no value is found in an option file for a parameter, its
default value is used as indicated in the descriptions given
earlier in this section.
Syntax
MYSQL *mysql_real_connect(MYSQL *mysql, const char
*host, const char *user, const char *passwd, const char *db,
unsigned int port, const char *unix_socket, unsigned long
client_flag)
Example
MYSQL mysql;
mysql_init(&mysql);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name");
if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
{
fprintf(stderr, "Failed to connect to database: Error: %s\n",
mysql_error(&mysql));
}
Output / Return Value
A MYSQL* connection handle if the connection
was successful, NULL if the connection was
unsuccessful. For a successful connection, the return value is
the same as the value of the first parameter.MYSQL*NULL
Limitations
Alternatives / See Also
Reference