w3schools    w3Schools
Search :
   
HOME HTML CSS XML JAVASCRIPT ASP PHP SQL MORE...   References Examples Forum About
ADVERTISEMENTS

XML Certification
Download XML editor
Custom Programming
 
Table of contents
PHP Basic
PHP HOME
PHP Intro
PHP Install
PHP Syntax
PHP Variables
PHP String
PHP Operators
PHP If...Else
PHP Switch
PHP Arrays
PHP Looping
PHP Functions
PHP Forms
PHP $_GET
PHP $_POST

PHP Advanced
PHP Date
PHP Include
PHP File
PHP File Upload
PHP Cookies
PHP Sessions
PHP E-mail
PHP Secure E-mail
PHP Error
PHP Exception
PHP Filter

PHP Database
MySQL Introduction
MySQL Connect
MySQL Create
MySQL Insert
MySQL Select
MySQL Where
MySQL Order By
MySQL Update
MySQL Delete
PHP ODBC

PHP XML
XML Expat Parser
XML DOM
XML SimpleXML

PHP and AJAX
AJAX Introduction
XMLHttpRequest
AJAX Suggest
AJAX XML
AJAX Database
AJAX responseXML
AJAX Live Search
AJAX RSS Reader
AJAX Poll

PHP Reference
PHP Array
PHP Calendar
PHP Date
PHP Directory
PHP Error
PHP Filesystem
PHP Filter
PHP FTP
PHP HTTP
PHP Libxml
PHP Mail
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip

PHP Quiz
PHP Quiz
PHP Exam

Selected Reading
Web Statistics
Web Glossary
Web Hosting
Web Quality

Browse Tutorials
 

PHP mysql_pconnect() Function


PHP MySQL Reference Complete PHP MySQL Reference

Definition and Usage

The mysql_pconnect() function opens a persistent MySQL connection.

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.

mysql_pconnect() is much like mysql_connect(), but with two major differences:

  • 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

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"
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_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


Tips and Notes

Tip: To establish a non-persistent MySQL connection, use mysql_connect() instead.


Example

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


PHP MySQL Reference Complete PHP MySQL Reference