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

Related Questions

I've reviewed a couple options for jquery-based RTE that required PHP. I'm running a
From couple of days i am thinking of a following scenario Consider I have
I want to start a couple of jobs on different machines using ssh. If
I have read a couple of articles about the using statement to try and
I'd like to have a simple select input box with a couple options for
I have a form with a couple search options, like a checkbox array and
I have a drop-down where users can select a couple of options. Can I
I code according to JSLint standards (excluding a couple of options) and I thought
I need to pass an NSDictionary with a couple of options to NSAlert -
Couple of months ago, we revamped our web site. We adopted totally new site

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.