PHP mysql_pconnect() 函数

定义和用法

mysql_pconnect() 函数打开一个到 MySQL 服务器的持久连接。

mysql_pconnect() 和 mysql_connect() 非常相似,但有两个主要区别:

  1. 当连接的时候本函数将先尝试寻找一个在同一个主机上用同样的用户名和密码已经打开的(持久)连接,如果找到,则返回此连接标识而不打开新连接。
  2. kware, bayan da takaddama a baya ya kammala, haɗin kan SQL server a kai yace za a zama buɗe don ci gaba da samun fada (mysql_close() ɗan zai mayar da haɗin kan da mysql_pconnect() a tsara).

kalama

mysql_pconnect(server,user,pwd,clientflag)
tunan ba'a nuna amince
server

zai tsawon kai. ce mai nuna amince wanda ake haɗa da server.

iya ce mai a cikakawa amince, misali "hostname:port", tana kuma zuwa hanyar zuwa soket gida, misali sosai localhost ":/path/to/socket".

If the PHP instruction mysql.default_host is not defined (the default case), the default value is 'localhost:3306'.

user Optional. Username. The default value is the username of the server process owner.
pwd Optional. Password. The default value is an empty password.
clientflag

Optional.clientflags The parameter can be a combination of the following constants:

  • MYSQL_CLIENT_SSL - Uses SSL encryption
  • MYSQL_CLIENT_COMPRESS - Uses a compressed protocol
  • MYSQL_CLIENT_IGNORE_SPACE - Allows spaces after the function name
  • MYSQL_CLIENT_INTERACTIVE - Allows closing the connection before the interactive timeout inactive time

Return Value

If successful, it returns a MySQL persistent connection identifier, and returns FALSE if an error occurs.

Tips and Notes

Note:Optional parameter clientflag Available since PHP 4.3.0 version.

Tip:To create a non-persistent connection, use mysql_connect() Function.

Example

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