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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:26:48+00:00 2026-06-16T13:26:48+00:00

I’m kinda going crazy about this problem. I can’t do it myself so I

  • 0

I’m kinda going crazy about this problem. I can’t do it myself so I need the community to help me get this thing solved. I’ve been spending hours on this because I didn’t know where to look. I now know a possible fix but it’s just messy (read on). I just need someone who knows more about this than I do.

This is my situation:

  • I want to use 2 or more mysql connections.
  • I use OOP

I have a class called dbase, it has two functions, setConnection and getConnection and two class variables called $connection and $dbaseName.

In my main project file I include dbase and create two objects:

  • dbase
  • maindbase

then I do:

$this->dbase->setConnection($server, $uname, $pword);
$this->maindbase->setConnection($server, $uname, $pword);

the setConnection function looks like this:

function setConnection ($server, $serv_Username, $serv_Password) {
    $this->connection = mysql_connect($server, $serv_Username, $serv_Password, true);
    // echo $this->connection . "<BR>";
}

I echo it to see the resourcenumber and added true to mysql_connect (and I know it’s deprecated since 5.5, I’m not here for that).

Now, as I understand OOP, the class variables are set per object. So $connection from dbase will never be the same as maindbase (unless, of course, I use the same credentials, but even then it will create a new link because of the $new_link option I enabled). They both have different resource ID’s.

My problem:

In class dbase I also have a function which runs a query like this:

$connection = $this->getConnection();
$dbase_name = $this->getDbaseName();
mysql_select_db($dbase_name, $connection); 
$q = "SELECT * FROM {$table_name} WHERE {$column} LIKE '{$value}'";
$result = mysql_query($q);

Now, when I use it like this, it will ALWAYS use the FIRST $connection that has been set in class dbase and it doesn’t matter which object this is, either object dbase or maindbase.

I get this error:

Table 'testdbase1.skye_domains' doesn't exist

object dbase is connected to testdbase1

object maindbase is connected to testdbase2

the above error I get when trying to select results using the maindbase object.

When I remove the $connection string from mysql_select_db it works perfectly because it will try to open a new connection as if using mysql_connect.

Why is this? This is impossible right? How can objectmaindbase have the same $connection as object dbase? They are in NO WAY connected to eachother… Is PHP somehow using a global mysql_connect variable or buffer which I’m not aware about?

I would like to keep using connectionstrings as this is just handy now and then. Leaving the $connection string out seems messy.

Does anybody have any suggestions I can try to make PHP (or my head) sane again?

  • 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-16T13:26:49+00:00Added an answer on June 16, 2026 at 1:26 pm

    Try to put echo $this->connection EVERYWHERE you use it. Also, create an “id” member and fill it with a unique value upon constructing a dbase-object and echo it along the value of $this->connection. This way you can track where what happens to your connection.

    And check if there’s maybe some place outside of the class that assigns $foo->connection. If you’re not using “private” on the members, you’re bound to have such problems when you e.g. forget to remove a hack or an experiment from unrelated parts of your code.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.