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 8079317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:03:57+00:00 2026-06-05T16:03:57+00:00

Possible Duplicate: Do I really need to do mysql_close() Maybe the first question to

  • 0

Possible Duplicate:
Do I really need to do mysql_close()

Maybe the first question to ask is, do I even need to close my MySQL connections? Is this something that is done automatically at the end of each script?

Anyway, in the example below, you can see if you call DoOtherStuff() from DoStuff(), your database connection is closed before you can run the MySQL query right after the call to DoOtherStuff(). Now, what is the rule for opening and closing MySQL connections? Can I just not close any connections and open a connection whenever a function requires it? Will this create more than necessary database connections and make my code slower? Any tips for this? I’m just doing what feels best, I feel a little lost.

function DoStuff(){
    $connection = mysql_connect(...);

    DoOtherStuff();

    mysql_query(...);//This won't run

    mysql_close($connection);
}

function DoOtherStuff(){
    $connection = mysql_connect(...);

    //Does other stuff

    mysql_close($connection);
}
  • 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-06-05T16:03:58+00:00Added an answer on June 5, 2026 at 4:03 pm

    No, you dont have to close your connection. As per the manual:

    Using mysql_close() isn’t usually necessary, as non-persistent open
    links are automatically closed at the end of the script’s execution.
    See also freeing resources.

    Most applications only have one database connections, so actually storing the connection resource isnt needed either.

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

Sidebar

Related Questions

Possible Duplicate: Do I really need version control? My question is simple enough. When
Possible Duplicate: Need help solving Project Euler problem 200 Similar to this question Project
Possible Duplicate: What is this weird colon-member syntax in the constructor? I need to
Possible Duplicate: Property Declaration and Automatic Backing Storage Allocation I'm really confused about this
Possible Duplicate: Do I really need to encode '&' as ' &' ? I
Possible Duplicate: How to catch exceptions I have not really had to use try
Possible Duplicate: What does 'foo' really mean? I hope it is not the most
Possible Duplicate: private members in python I've got few variables I really want to
Possible Duplicates: iPhone development on PC iPhone development on Windows Do I really need
Possible Duplicate: Why we need Thread.MemoryBarrier()? From O'Reilly's C# in a Nutshell: class Foo

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.