当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > mysql_pconnect() 函数

PHP
PHP 介绍
PHP 安装
PHP 语法
PHP 变量
PHP操作符
PHP If...Else
PHP Switch
PHP 数组
PHP 循环
PHP 函数
PHP 表单
PHP $_GET
PHP $_POST
PHP Date
PHP Include
PHP 文件处理
PHP 文件上传
PHP Cookies
PHP Sessions
PHP 发送邮件

PHP 中的 mysql_pconnect() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 524 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The mysql_pconnect() function opens a persistent MySQL connection.
mysql_pconnect()函数的作用是:打开一个到 MySQL 服务器的持久连接。

This function returns the connection on success, or FALSE and an error on failure. You can hide the error output by adding an '@' in front of the function name.
如果这个函数成功执行,将返回这个连接;如果发生错误,将返回False。你可以通过在函数名称前面加上一个“@”符号来隐藏错误结果。

mysql_pconnect() is much like mysql_connect(), but with two major differences:
mysql_pconnect()函数和mysql_connect()函数非常相像,但是仍然存在两点差异:

  • This function will try to find a connection that's already open, with the same host, username and password. If one is found, this will be returned instead of opening a new connection
    这个函数将试图查找通过使用相同的主机、用户名以及密码打开的连接;如果他已经找到了一个连接,那么它将不再打开新的连接。
  • The connection will not be closed when the execution of the script ends (mysql_close() will not close connection opened by mysql_pconnect()). It will stay open for future use
    当脚本程序执行完毕时,该连接也不会关闭(可使用mysql_close()函数关闭通过mysql_pconnect()函数打开的连接)。它将在以后继续使用。

Syntax
语法

mysql_pconnect(server,user,pwd,clientflag)

Parameter参数 Description描述
server Optional. Specifies the server to connect to (can also include a port number. e.g. "hostname:port" or a path to a local socket for the localhost). Default value is "localhost:3306"
可选参数。指定需要连接的服务器(他可以包含一个端口号。案例:“hostname:port”,或者一个连接到本地服务器的路径)。默认值为:“localhost:3306”
user Optional. Specifies the username to log in with. Default value is the name of the user that owns the server process
可选参数。指定登陆的用户名。默认的用户名是该服务器拥有者的名字
pwd Optional. Specifies the password to log in with. Default is ""
可选参数。指定登陆的密码。默认值为""
clientflag Optional. Can be a combination of the following constants:
可选参数。可以使用的值如下:
  • MYSQL_CLIENT_SSL - Use SSL encryption
    MYSQL_CLIENT_SSL – 使用SSL技术加密
  • MYSQL_CLIENT_COMPRESS - Use compression protocol
    MYSQL_CLIENT_COMPRESS – 使用压缩[compression]协议
  • MYSQL_CLIENT_IGNORE_SPACE - Allow space after function names
    MYSQL_CLIENT_IGNORE_SPACE – 允许在函数名称后面出现空格
  • MYSQL_CLIENT_INTERACTIVE - Allow interactive timeout seconds of inactivity before closing the connection
    MYSQL_CLIENT_INTERACTIVE – 在关闭连接之前,允许对休止状态下的函数设置激活时间


Tips and Notes
提示

Tip: To establish a non-persistent MySQL connection, use mysql_connect() instead.
提示:你可以使用mysql_connect()函数建立一个非持续的MySQL连接[non-persistent MySQL connection]


Example
案例

<?php
$con = mysql_pconnect("localhost","mysql_user","mysql_pwd");
if (!$con) { die('Could not connect: ' . mysql_error()); }
?>

评论 (0) All

登陆 | 还没注册?