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

  • SEARCH
  • Home
  • 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 7888675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:53:35+00:00 2026-06-03T05:53:35+00:00

When I was writing PHP code with PDO and MySQL, I would always create

  • 0

When I was writing PHP code with PDO and MySQL, I would always create connections when I needed them within functions like so:

result pseudo_function() {
  create and open connection
  do stuff
  close connection
  return result
}

Now, I started programming in C, I have seen that pointers are an interesting way to pass the entire connection as parameter to the function. I was wondering if it would be better to pass the connections between functions until the entire user request is served.

To clarify: For one user request, there could be 1-5 calls to a function that then opens a database, fetches data, does something, closes and returns.

Also does it make a difference performance wise if you keep a connection opened?

  • 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-03T05:53:37+00:00Added an answer on June 3, 2026 at 5:53 am

    The “standard idiom” for most PHP code I’ve seen seems to be “open the connection, and leave it open”.

    php.net seems to be down at the moment, but these two links might be of interest:

    • http://php.net/manual/en/function.mysql-pconnect.php

    • http://php.net/manual/en/mysqlnd-ms.pooling.php

    If you’re running Apache, perhaps mod_dbd might be a good solution:

    • http://httpd.apache.org/docs/2.2/mod/mod_dbd.html

    Here’s a good discussion on the implications of not closing your connections:

    • Is it totally reckless to leave mysql connection open through a page?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While writing code in a file that would comprise of PHP, HTML, CSS &
What is faster: writing PHP code using functions or writing it as pure script?
I am writing some PHP code to create PDFs using the FPDF library. And
I have found that writing PHP code within classes can become rather long: $this->parser->parse_syntax($this->get_language_path($this->language),
i am writing a php code involving mysql. At one point, i have to
I have been writing php and mySQL functions all day and as I was
In my php code, I am writing a class to create log files, and
When writing PHP code for any given project, do you find you can write
I am writing PHP code where I want to pass the session id myself
I'm currently re-writing one of my old PHP scripts so that the code is

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.