PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




mysql_pconnect() function for PHP


Tutorials »Php »

Topic

What is mysql_pconnect() function in PHP?
How does mysql_pconnect() works?




Explanation

Mysql function mysql_pconnect() opens a persistent connection to a MySQL server.

Syntax

resource mysql_pconnect ( [string server [, string username [, string password [, int client_flags]]]])


string server (optional): server to connect, includes Desired host, with optional port or socket component
string user_name (optional): Username to log in with
string password (optional): Password to log in with
int client_flags (optional): Can be a combination of the following constants:
  • MYSQL_CLIENT_SSL - Use SSL encryption
  • MYSQL_CLIENT_COMPRESS - Use compression protocol
  • MYSQL_CLIENT_IGNORE_SPACE - Allow space after function names
  • MYSQL_CLIENT_INTERACTIVE - Allow interactive timeout seconds of inactivity before closing the connection

Returns a positive MySQL persistent link identifier on success, or FALSE on error.

mysql_pconnect() establishes a connection to a MySQL server.

mysql_pconnect() works same as mysql_connect with two differences.

First, when connecting, the function would first try to find a (persistent) link that is already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

Second, Mysql_connect opens a new connection each time a PHP page is called up, and closes the connection down again at the end of the request. Mysql_pconnect() will also open a new connection when a PHP page is called up (at any rate, it will the first time after a server reboot), but it will NOT close the connection at the end of the request - instead, it will save it in a connection pool so that a subsequent request can continue to use the same connection.

Example:


<?php

$link = mysql_pconnect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");

?>



If you want to establish a non-persistent MySQL connection, use mysql_connect() instead.





Other Links

web hosting