Both mysql_connect() and mysql_pconnect() are used for database connection.
mysql_connect()
In mysql_connect() function opens and close the database connection, depending on the request. Every time a new connection is established, when using mysql_connect().
Closing of the connection is compulsory in mysql_connect(). This can not be accessed by another database.
Syntax of mysql_connect()-
Mysql_connect('localhost'); |
Below is the example:-
<?php
//use for connection
{
$con= mysql_connect('localhost');
echo "$con";
}
?>
mysql_pconnect()
In mysql_pconnect() 'p' stands for persistent. In this a new connection is not established. During the connection the function checks that if there is any connection with the same host, username and password, then it will use it inspite of opening the new connection.
In this there is no need to close the connection.
There is no need to be remain connected with database everytime.
This function helps in making the site efficient and reduce the traffic.
Syntax of mysql_pconnect()-
Mysql_pconnect('localhost'); |
Below is the example:
<?php
//use for persistence connection
$conn = mysql_pconnect('localhost');
echo $conn;
?>
The output of both the function will be same.
0 Comment(s)