What's the difference between Mysql_ Pconnect and mysql_connect?

Source: Internet
Author: User
Tags pconnect
MySQL database PHP

The manual says there are two major differences.
1. Do not repeatedly make connection requests
2.mysql_close doesn't work.

The 1th is a little confused. That is not my mysql_connect not to make a request or halfway mysql_close is like Mysql_ pconnect.

If that's the case

Then I define a function

function Connect () {

Static $connect _id;
if (! $connect _id)
$connect _id = mysql_connect ("localhost", "Hao", "Hao");
return $connect _id;

}
Call this function outside to connect to the database. Connect ()
There will be no duplicate connection requests.
Is that the same as Mysql_ pconnect?

Welcome to answer Thank you


Reply to discussion (solution)

Resource mysql_connect ([string $server [, String $username [, String $password [, bool $new _link [, int $client _flags]] ]]] )

When you do not specify a true value for the $new _link, their behavior is the same. The second call of the same parameter will not establish a new connection, but will return the connection ID that has already been opened

That is not my mysql_connect not to make a request or halfway mysql_close is like Mysql_ pconnect.
No!
Database connectivity is divided into two stages
First stage: Establishing a physical connection to the database server
Phase II: Log in to the database server and establish a business link to the database

For Mysql_connect, Mysql_close will sever the two connections (the PHP program will automatically call Mysql_close when it ends)
does not work for mysql_pconnect,mysql_close. After the end of the PHP program, automatically cut off the business link to the database. And keep the physical connection ready for reuse

That is not my mysql_connect not to make a request or halfway mysql_close is like Mysql_ pconnect.
No!
Database connectivity is divided into two stages
First stage: Establishing a physical connection to the database server
Phase II: Log in to the database server and establish a business link to the database

For Mysql_connect, Mysql_close will sever the two connections (the PHP program will automatically call Mysql_close when it ends)
does not work for mysql_pconnect,mysql_close. After the end of the PHP program, automatically cut off the business link to the database. And keep the physical connection ready for reuse

Moderator Thank you for your answer. I don't quite understand what you mean by mysql_pconnect reuse. Can I use cross script to reuse No. For example, a script uses mysql_pconnect, and then the B script is opened when the a script is not finished. The B script can use a connection to a script without having to connect to the database again.

What are the advantages of mysql_pconnect? I see some online database operation classes; it's useless.
Do not know the role of a big little.

Database connections are always necessary
Usually the network connection is slow, that is, if you do not cut off the physical connection to the database, the next visit may be faster (provided that the last connection when the network channel can be reused)
Long connections are generally used when the Web service is not on the same machine as the database service

As you described, "script B when the script A is not finished" case, is not reusable connection, because the premise of reuse is that the connection is in an idle state

Database connections are always necessary
Usually the network connection is slow, that is, if you do not cut off the physical connection to the database, the next visit may be faster (provided that the last connection when the network channel can be reused)
Long connections are generally used when the Web service is not on the same machine as the database service

As you described, "script B when the script A is not finished" case, is not reusable connection, because the premise of reuse is that the connection is in an idle state

Thank you moderator I probably understand.
I'm going to think about that for a second.
Long connections are generally used when the Web service is not on the same machine as the database service

As I said before, it's not the same machine, it's over the network.
And the network is not for you to use one person, so the actual connection is relatively slow. So keep the physical connection (even if you don't let go) it's cost-effective.
And on the same machine and on, because it does not need to go through the network, so relatively fast. Instead, long connections are too late to be idle, crowding out a lot of resources, causing the database to not connect

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.