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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:50:59+00:00 2026-05-10T17:50:59+00:00

A couple of the options are: $connection = {my db connection/object}; function PassedIn($connection) {

  • 0

A couple of the options are:

$connection = {my db connection/object};  function PassedIn($connection) { ... }  function PassedByReference(&$connection) { ... }  function UsingGlobal() {     global $connection;     ... } 

So, passed in, passed by reference, or using global. I’m thinking in functions that are only used within 1 project that will only have 1 database connection. If there are multiple connections, the definitely passed in or passed by reference.

I’m thining passed by reference is not needed when you are in PHP5 using an object, so then passed in or using global are the 2 possibilities.

The reason I’m asking is because I’m getting tired of always putting in $connection into my function parameters.

  • 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. 2026-05-10T17:50:59+00:00Added an answer on May 10, 2026 at 5:50 pm

    I use a Singleton ResourceManager class to handle stuff like DB connections and config settings through a whole app:

    class ResourceManager {     private static $DB;     private static $Config;      public static function get($resource, $options = false) {         if (property_exists('ResourceManager', $resource)) {             if (empty(self::$$resource)) {                 self::_init_resource($resource, $options);             }             if (!empty(self::$$resource)) {                 return self::$$resource;             }         }         return null;     }      private static function _init_resource($resource, $options = null) {         if ($resource == 'DB') {             $dsn = 'mysql:host=localhost';             $username = 'my_username';             $password = 'p4ssw0rd';             try {                 self::$DB = new PDO($dsn, $username, $password);             } catch (PDOException $e) {                 echo 'Connection failed: ' . $e->getMessage();             }         } elseif (class_exists($resource) && property_exists('ResourceManager', $resource)) {             self::$$resource = new $resource($options);         }     } } 

    And then in functions / objects / where ever:

    function doDBThingy() {     $db = ResourceManager::get('DB');     if ($db) {         $stmt = $db->prepare('SELECT * FROM `table`');         etc...     } } 

    I use it to store messages, error messages and warnings, as well as global variables. There’s an interesting question here on when to actually use this type of class.

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

Sidebar

Ask A Question

Stats

  • Questions 239k
  • Answers 239k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I found out why this downlevel behaviour was happening. ASP1.1… May 13, 2026 at 7:00 am
  • Editorial Team
    Editorial Team added an answer In general, you always should do server-side data valdation. This… May 13, 2026 at 7:00 am
  • Editorial Team
    Editorial Team added an answer You probably want to read up on slice. Your code… May 13, 2026 at 7:00 am

Related Questions

I have a stored procedure which takes an XML parameter and inserts the data
I have a webform with quite a few fields (between 15 to 40, based
We have a local database of our products without the price. To get the
I'm a PHP newbie working a some scripts to display some news articles from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.