Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6195331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:27:03+00:00 2026-05-24T03:27:03+00:00

I am using PHP to query the MySQL database on my website. Please answer

  • 0

I am using PHP to query the MySQL database on my website. Please answer the following questions:

  1. What will happen if I don’t use mysql_close() when I am done with querying the database in the end? The connection will remain open? If yes then upto how much time? If no then why?
  2. If I open and close a connection to MySQL at several places in a
    webpage, how is the performance affected? i.e. connection is made again everytime some access to database is required on a single webpage.
  3. How is mysql_close() related to performance? Should I open a new connection everytime some access to database is required OR should I keep only one connection and close it in the end?
  4. If I don’t close the connection, then if the user is trying to
    access some data again, will the new connection be used or the old
    open connection will be used?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:27:04+00:00Added an answer on May 24, 2026 at 3:27 am
    1. It will automatically close when the PHP script is done running during destruct phase.
    2. Performance will negatively be affected. Opening a new socket (especially to an external database server) is more expensive and time consuming than just keeping a pointer to the current connection in memory.
    3. See answer no. 2
    4. The access to the data will be performed by a new PHP request. Hence, you will have a new database connection. No problems there.

    I’d advise to open your database connection during construct phase, re-use that connection during the entire execution of your script (if it’s OO based, assign a class variable for your database connection and use $this->db during the entire script), and close it during destruction (or don’t bother at all closing it, as it will be closed anyway, even when not declared specifically).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am designing a website which will query a simple MySQL database using AJAX
I'm trying to create a simple database table using the PHP MySQL query Create
I am using PHP 5 to create a query page for a MySQL database
I am using php query to retrieve information from a mysql database with mysql_fetch_array
Using PHP I am able to query MySQL database and see the results echo
I have a webapp written in PHP using a MySQL database backend. This question
I would like to submit information to a mySql database using php and ajax.
I want to grab data from a mysql database by using php. The data
I am trying to display from a MySQL Database using PHP and Ajax but
I am using PHP, AS3 and mysql. I have a website. A flash(as3) website.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.