mysql_real_connect阻塞_mysql_real_connect 参数注意-阿里云开发者社区

mysql_real_connect函数用于建立与MySQL服务器的连接,其参数中的NULL和空字符串有特殊含义。若想从选项文件读取参数,host设为NULL或空字符串,user也如此,passwd设为NULL(因空字符串表示空密码),db设为NULL或空字符串,port设为0,unix_socket设为NULL。如果选项文件中未找到参数值,将使用默认值。
摘要由CSDN通过智能技术生成

mysql_real_connect的声明:

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)

以下是官网的解释,其中对于NULL,empty string,empty string("")之间的区间需要格外注意:

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.

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.

本文转自 XDATAPLUS 51CTO博客,原文链接:http://blog.51cto.com/xdataplus/1893422

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值