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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:54:43+00:00 2026-05-27T19:54:43+00:00

I have a class for each database table object. Each class takes care of

  • 0

I have a class for each database table object. Each class takes care of connection/queries/data format (database table specific logic) as I prefer to assign a connection for each class for better modularity. Also, I am using specific connections for some tables and queries.

My question is how can I check if a connection already exists so it won’t start another one?

Basically I want to check if the connection with the same username/password/database has already been made. Or is this not necessary because mySql won’t start a new connection for the same user? If that is so then please explain.

After further research found out that this is not possible … it would require to get the thread id and use the conn with the thread id and it would act like a persistant conn; Or it would require to keep track every thread ids used during a script and it’s kinda useless.

There isn’t yet a spimple method of doing this … persistant connection can be a choice but then u have to take care of connection clean up and again sux 🙂

P.S. : Eventually i did made a tracking system for the connections during my app run (the guys that said to store them in a globally available object we’re right). Stored conn object and conn params in 2 arrays in a singleton class object, checked if the params allready exists in params array , if not make new conn , if yes get the conn object from the array-key thats the same with the key where params were found… I allready had the arhitecture made for this but didnt want to use that class…not the logic i began with :), and also wanted to make it in a library item, thats why i was looking for a simple and abstract solution but there is only a particular solution 🙂

  • 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-27T19:54:44+00:00Added an answer on May 27, 2026 at 7:54 pm
    • Create new connection for each class is not a good idea. It may be modularized to you but your mysql server will be soon bloated with too may connections error.

    I suggest use singleton pattern and some OO.

    class Singleton{
        private static $instance=null;
        public function connection(){
            if(self::$instance==null){
                self::$instance = mysql_connect(); // define it in your way,
            }
            return self::$connection;
        }
    }
    
    class TableA extends Singleton{
        function find($id){
            $query="select * from `A` where `id`='$id'";
            mysql_query($query, $this->connection());
            ... // other codes
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently create a Repository for each database table and a corresponding data class
Basically I have some class objects, each with three properties. Once one class object
I have a number of objects, all from the same class(ColorNum) Each object has
I have done a few projects lately using a Database Object super class which
I have class Foo(): function bar(): pass function foobar(): pass Rather than executing each
I have a class with a custom each-method: class CurseArray < Array def each_safe
I have a class library containing several structures each consisting of several value and
I have a class that encapsulates tcp socket communications with a server. For each
I have a class Person which can have several Homes, each one with one
I have a manager class that produces tasks for a threadpool, and each thread

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.