Hi all,
Nobody knows what are the main differnce between MYSQL_CONNECT() and MYSQL_PCONNECT(). MYSQL_CONNECT() and MYSQL_PCONNECT() are working for database connection. But these two have some little diffrence. In mysql_pconnect(), ‘p’ stands for persistance connection.
The mysqli_connect() function opens a new connection to the MySQL server. Every time it is opening and closing the database connection, depending on the request .
SYNTAX
mysqli_connect(host,username,password,dbname,port,socket);
Mysql_pconnect checks if that if the same host, username and password connection is already opened an identifier for it will be returned instead of making a new connection. mysql_pconncet() is useful when you have a lot of traffice on your site
Difference between mysql_connect() and mysql_pconnect()
MYSQL_CONNECT()
- mysql_connect can be used to close the connection.Every time it is opening and closing the database connection, depending on the request .
- Here database is opened everytime when the page is loaded in MYSQL connect
- When the page is loaded, the database is loaded everytime
- It is used to close the connection
-
Example:<
?php
$conn = mysql_connect(‘host’, ‘mysql_user’, ‘mysql_password’);
if (!$conn)
{
die(‘Could not connect: ‘ . mysql_error());
}
echo ‘Connected successfully’;
mysql_close($conn);
?>
Description:- host: Specifies a host name or an IP address like localhost.
- mysql_user: Specifies the MySQL username
- mysql_password: Specifies the MySQL password
MYSQL_PCONNECT()
- We use the mysql_pconncet(), it initially tries to find an open persistent connection.
- The mysql_pconncet() opens persistant connection
- The mysql_pconnect() does not support the close connection
- mysql_pconnect() cannot close the connection. Here open a persistant connection to the database
- Here database need not be connected everytime.
- The database need not be connected every time in mysql_pconncet().
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.