Quote
When user1 visits a page, the page get connect with mysql.
When user2 visits the same page, Is the page connect with mysql again?
Yes.
Quote
Imagine user1 visits a page, at the same time if user2 visit the same page. So that page is connect with mysql. So when user1 leave the page and mysql gets disconnected, how user2 still can get the page is connected with mysql?
A web server can (and will) open
many connections to
many databases every time a page is accessed.
Whatever the site's code tells it to do will be done for each and every request, by each and every user. These connections are, of course,
separate.
Quote
So when user1 leave the page ...
I think you
misunderstand how a Web Application works.
User1 opens their Web Browser and navigates to the URL.
The Web Server receives this [HTTP] request, runs some code, which opens connections, does some "stuff", closes those connections (if it's well-written) and sends the result (usually HTML) back to the User's browser.
(Apart from any "Session" data), the Web Server then
forgets all about that request
and the User that made it and goes back to just waiting for something to do. This is called
Stateless processing. Each request is, in theory, completely independent from every other, even by the same User.
Just because a Web Page is sitting on front on you in a browser, does not mean that the Web Server is doing
anything at all about it.
It's only when you make another
request - clicking on a link or a button or something else that needs the Web Server to "do" something - that the Web Server will take any notice of you again.
The same goes for User2, and all the other Users that you support. They all sending requests, which the Web Server processes and returns "stuff" back to the browser.
Regards, Phill W.