mysql_ssl_set() before calling mysql_real_connect().
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:
*
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.
If 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.
Return Values
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。当成功时,返回值和第一个参数值是// 相同的。
Errors
*
CR_CONN_HOST_ERROR
Failed to connect to the MySQL server.
*
CR_CONNECTION_ERROR
Failed to connect to the local MySQL server.
*
CR_IPSOCK_ERROR
Failed to create an IP socket.
*
CR_OUT_OF_MEMORY
Out of memory.
*
CR_SOCKET_CREATE_ERROR
Failed to create a Unix socket.
*
CR_UNKNOWN_HOST
Failed to find the IP address for the hostname.
*
CR_VERSION_ERROR
A protocol mismatch resulted from attempting to connect to a server with a client
library that uses a different protocol version. This can happen if you use a very old
client library to connect to a new server that wasn't started with the --old-protocol
option.
*
CR_NAMEDPIPEOPEN_ERROR
Failed to create a named pipe on Windows.
*
CR_NAMEDPIPEWAIT_ERROR
Failed to wait for a named pipe on Windows.
*
CR_NAMEDPIPESETSTATE_ERROR
Failed to get a pipe handler on Windows.
*
CR_SERVER_LOST
If connect_timeout > 0 and it took longer than connect_timeout seconds to connect to
the server or if the server died while executing the init-command.
因此mysql_real_connect()函数调用为:
mysql_real_connect(mysql,"localhost","root",NULL,"test",0,NULL,0);
判断是否出错,出错调用mysql_error()函数显示出错信息,或使用mysql_errno()函数获取出错代号。
http://blog.csdn.net/newrain021011/archive/2007/03/05/1521622.aspx
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




