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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:49:00+00:00 2026-05-11T20:49:00+00:00

I seem to go back and forth on this, sometimes it works for me,

  • 0

I seem to go back and forth on this, sometimes it works for me, often it doesn’t and I can’t figure out how/why I can get it to work sometimes, and at other times it won’t.

I have 5 databases, and need to grab data from each of them during a maintenance routine.
For each of the databases, I have an external file which contains all the db connection code which I include in my page.

The includes look like this

$SGcon = mysql_connect("localhost","root","");

if (!$SGcon)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("sGopen", $SGcon);

For each database I provide a different varaible, so the next database will be

$PTcon = mysql_connect("localhost","root","");

if (!$PTcon)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("pTsecond", $PTcon);

Then when i call my query, I use

 
mysql_query($getQuery,  $PTcon);
mysql_query($secondQuery, $SGcon);

The problem I’m running into is that I’m not getting the correct database used for the query , it seems my script is using the databases which was added to the page last.

Is there a better way for me to switch the database connection to be used?

There is lots of back and forth between the databases as I’m comparing data from one db to data in another, so i’m trying to be efficient with this as well.

Thanks
Pete

  • 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-11T20:49:00+00:00Added an answer on May 11, 2026 at 8:49 pm

    By default, if you pass the same arguments to mysql_connect as a previous call it’ll return a cached connection if available, rather than creating a new one. So both queries are running against whichever database you last passed to mysql_select_db.

    Passing new_link=true will avoid this behaviour, although database connections can be expensive so you should try to keep as few open as reasonably possible.

    The detailed explanation for new_link:

    If a second call is made to
    mysql_connect() with the same
    arguments, no new link will be
    established, but instead, the link
    identifier of the already opened link
    will be returned. The new_link
    parameter modifies this behavior and
    makes mysql_connect() always open a
    new link, even if mysql_connect() was
    called before with the same
    parameters. In SQL safe mode, this
    parameter is ignored.

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

Sidebar

Related Questions

I've gone back and forth on this problem and can't seem to figure out
I can't seem to get back on track with this one. I simply put
I can't seem to figure this out for the life of me. I have
I keep coming back to this problem, since there doesn't seem to be a
I have seen the solution to this a while back, but can't seem to
This is a fairly easy one, but I cant seem to figure it out.
I just can't seem to get this working its been weeks I've been trying.
I cannot seem to make this simple code work: <script type=text/javascript> $(document).ready(function(){ $.getJSON('http://maps.google.com/maps/api/geocode/json?address=cebu&sensor=false&region=ph', function(results)
Depending on my mood I seem to waffle back and forth between wanting a
I seem to have this pattern occuring pretty often in my code, with two

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.