The function mysql_connect() establishes the connection to MySQL. To establish the connection, the host name, database user and password is needed. The host is usually a localhost. But how To use mysql_pconnect?
-
2I don't know the difference, only that you shouldn't use them, mysql is outdated and not secure – Epodax Feb 17 '15 at 11:09
-
3possible duplicate of [mysql\_connect VS mysql\_pconnect](http://stackoverflow.com/questions/247807/mysql-connect-vs-mysql-pconnect) *but don't use either!* Use PDO instead, or mysqli_* if you really must. – Dan Smith Feb 17 '15 at 11:14
2 Answers
Pretty much the same except for two major differences.
First, when connecting, the function would first try to find a (persistent) link that's 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, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).
This type of link is therefore called 'persistent'.

- 34,836
- 11
- 47
- 77
The hostname,username and password is also needed in mysql_pconnect()
but the difference is simply like a shop when you entering you will open the door and take your item, come out and close the door this is called mysql_connect()
, when code terminates, connection to mysql database will be automatically closed.
When the door of the shop is already opened and never closed it is called mysql_pconnect()
, so it mean the connection to mysql database will not be closed and will persist
for future use.

- 350
- 2
- 10