当前位置:首页 > 系统运维 > 正文内容

MySQL数据库中MySQL_real_connect的基本设置

a8116255316年前 (2010-06-11)系统运维9

此文章主要向大家讲述的是MySQL数据库中的MySQL_real_connect 连接参数的基本设置,我们在前一篇文章讲述关于进行MySQL(和PHP搭配之更佳组合)源程序代码的编译链接,但是没有讲述运行情况,在按照上一篇文章代码下进行编译运行后。

发现无法链接数据库文件,显然是在MySQL(和PHP搭配之更佳组合)_real_connect()函数中出现了问题。在MySQL(和PHP搭配之更佳组合)的英文手册中找到关于MySQL(和PHP搭配之更佳组合)_real_connect()的如下描述:

函数原型描述 MySQL数据库*MySQL(和PHP搭配之更佳组合)_real_connect(MySQL(和PHP搭配之更佳组合) *MySQL(和PHP搭配之更佳组合), const char *host, const char

*user,   const char *passwd, const char *db, unsigned int port, const char *unix_socket,   unsigned long client_flag)  Description  MySQL(和PHP搭配之更佳组合)_real_connect() attempts to establish a connection to a MySQL(和PHP搭配之更佳组合) database engine   running on host. MySQL(和PHP搭配之更佳组合)_real_connect() must complete successfully before you can   execute any other API functions that require a valid MySQL(和PHP搭配之更佳组合) connection handle structure.  The parameters are specified as follows:  *  The first parameter should be the address of an existing MySQL(和PHP搭配之更佳组合) structure. Before  calling MySQL(和PHP搭配之更佳组合)_real_connect() you must call MySQL(和PHP搭配之更佳组合)_init() to initialize the MySQL(和PHP搭配之更佳组合)   structure. You can change a lot of connect options with the MySQL(和PHP搭配之更佳组合)_options() call.   See Section 17.2.3.47, Â“MySQL(和PHP搭配之更佳组合)_options()”.  *  The value of host may be either a hostname or an IP address. If host is NULL or the   string "localhost", a connection to the local host is assumed. If the OS supports sockets   (Unix) or named pipes (Windows), they are used instead of TCP/IP to connect to the server.  *  The user parameter contains the user's MySQL(和PHP搭配之更佳组合) 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 username must be specified explicitly. See Section 18.1.9.2,  Â“Configuring a MyODBC DSN on Windows”.  *  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 allows the database administrator to set up the MySQL(和PHP搭配之更佳组合) 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(和PHP搭配之更佳组合)_real_connect();  password encryption is handled automatically by the client API.  *  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 that should  be used. 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:  

上面描述了五个参数的主要取值,MySQL数据库 *为MySQL(和PHP搭配之更佳组合)_init函数返回的指针,host为null或 // localhost时链接的是本地的计算机,当MySQL(和PHP搭配之更佳组合)默认安装在unix(或类unix)系统中,root账户是没// 有密码的,因此用户名使用root,密码为null,当db为空的时候,函数链接到默认数据库,在进行 // MySQL(和PHP搭配之更佳组合)安装时会存在默认的test数据库,因此此处可以使用test数据库名称,port端口为0,使用 // unix连接方式,unix_socket为null时,表明不使用socket或管道机制,最后一个参数经常设置为0

Flag Name Flag Description  CLIENT_COMPRESS Use compression protocol.  CLIENT_FOUND_ROWS Return the number of found (matched) rows, not the number of  changed rows.  CLIENT_IGNORE_SPACE Allow spaces after function names. Makes all functions names   reserved words.  CLIENT_INTERACTIVE Allow interactive_timeout seconds (instead of wait_timeout   seconds) of inactivity before closing the connection. The client's session wait_timeout   variable is set to the value of the session interactive_timeout variable.  CLIENT_LOCAL_FILES Enable LOAD DATA LOCAL handling.  CLIENT_MULTI_STATEMENTS Tell the server that the client may send multiple   statements in a single string (separated by Â‘;Â’). If this flag is not set,   multiple-statement execution is disabled. Added in MySQL(和PHP搭配之更佳组合) 4.1.  CLIENT_MULTI_RESULTS Tell the server that the client can handle multiple result   sets from multiple-statement executions or stored procedures. This is automatically   set if CLIENT_MULTI_STATEMENTS is set. Added in MySQL(和PHP搭配之更佳组合) 4.1.  CLIENT_NO_SCHEMA Don't allow the 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_ODBC The client is an ODBC client. This changes MySQL(和PHP搭配之更佳组合)d to be more  ODBC-friendly.  CLIENT_SSL Use SSL (encrypted protocol). This option should not be set by   application programs; it is set internally in the client library. Instead, use   MySQL(和PHP搭配之更佳组合)_ssl_set() before calling MySQL(和PHP搭配之更佳组合)_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(和PHP搭配之更佳组合)_real_connect() call. To do this, call   MySQL(和PHP搭配之更佳组合)_options() with the MySQL(和PHP搭配之更佳组合)_READ_DEFAULT_FILE or MySQL(和PHP搭配之更佳组合)_READ_DEFAULT_GROUP option   before calling MySQL(和PHP搭配之更佳组合)_real_connect(). Then, in the MySQL(和PHP搭配之更佳组合)_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(和PHP搭配之更佳组合)_real_connect() call cannot be overridden in an option file, because the empty   string indicates explicitly that the MySQL(和PHP搭配之更佳组合) 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  MySQL(和PHP搭配之更佳组合)* 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(和PHP搭配之更佳组合) server.  *  CR_CONNECTION_ERROR  Failed to connect to the local MySQL(和PHP搭配之更佳组合) 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 mi *** atch 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(和PHP搭配之更佳组合)_real_connect()函数调用为:

MySQL(和PHP搭配之更佳组合)_real_connect(MySQL数据库,"localhost","root",NULL,"test",0,NULL,0);

判断是否出错,出错调用MySQL(和PHP搭配之更佳组合)_error()函数显示出错信息,或使用MySQL(和PHP搭配之更佳组合)_errno()函数获取出错代号。

扫描二维码推送至手机访问。

版权声明:本文由2345好导航站长资讯发布,如需转载请注明出处。

本文链接:http://2345hao.cn/blog/index.php/post/21113.html

分享给朋友:

“MySQL数据库中MySQL_real_connect的基本设置” 的相关文章

上帝不止一个 更多Windows7 快捷模式.

上帝不止一个 更多Windows7 快捷模式.

国外媒体CNET NEWS就这个“上帝模式”和微软Windows部门主管Steven Sinofsky进行邮件交流后得知,这其实只是众多快捷方式中的一个,Sinofsky在邮件里给出了十多个这类快捷方式的关键字符串。 它们的建立方法和之前的“上帝模式”一样,在任意位置新建的一个文件夹,然后改名即可...

windows 7查看电脑近期使用情况确定有没有被他人使用

windows 7查看电脑近期使用情况确定有没有被他人使用

我一个朋友最近装装了Windows 7,他总感觉有人用了他的电脑,但是一直不确定,他想知道有没有人动用他的电脑,问我有没有办法 我说设置一下就行了: 启动Windows 7,在搜索栏中输入编辑组,马上就搜索到了编辑组策略,点击即可启动程序编辑组策略。依次展开组策略左侧树形列表的计算机配置/管理模...

各个都很实用:windows 7系统电脑日常小技巧

各个都很实用:windows 7系统电脑日常小技巧

在使用Windows 7的时候很多用户对于系统的很多功能并不是很了解,也正是因为这样的不了解导致很多用户在使用Win 之后并不能体验Windows 7的功能便携和强大功能,导致很多用户对于Windows 7的认识还是比较模糊,不过为了让更多的朋友了解Windows 7的特点和便携应用,今天就为大家汇...

Windows7截图出现黑屏导致截的图黑呼呼一片

Windows7截图出现黑屏导致截的图黑呼呼一片

最近一些Windows 7用户反馈说,自己在截屏的时候出现黑屏,导致自己截的图黑呼呼一片。这个问题该怎么解决?今天小编就为大家提供一个解决的方法。 步骤 1 在windows xp时代,很多用户都曾被视频截图后的“全黑图片”困扰。对此,在解决本地播放时出现的截图变黑问题,一般有两个方法可以用来解...

windows 7玩网游PING高即网络延时比较高的解决方法

windows 7玩网游PING高即网络延时比较高的解决方法

经常听见有人说用Windows 7玩网络游戏的时候网络延时比较高,也就是ping比平时xp的时候高一点,一直找不到原因,很苦恼。今天我们终于找到理由了,原来是Windows 7的一个服务在作怪,这个服务叫:Multimedia Class Scheduler,就是这个服务让我的PING如此高,问题是...

windows 7系统中不能把程序锁定到任务栏的解决方法图文讲解

windows 7系统中不能把程序锁定到任务栏的解决方法图文讲解

最近小编在使用Windows 7的时侯遇到一个问题,就是应用程序和快捷方式不能锁定到任务栏,我当时不知道怎么回事,但是很多现有的方法都不能解决这个问题。现在我把我的解决的方法分享给大家以作参考。 问题分析 经过思考,初步判断出现该问题的原因是由于使用第三方优化软件消除快捷方式的小箭头引起的。...