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 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

Ask A Question

Stats

  • Questions 243k
  • Answers 243k
  • 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 You should send it as HTTP header for squid to… May 13, 2026 at 7:49 am
  • Editorial Team
    Editorial Team added an answer It depends on whether you are trying to tell whether… May 13, 2026 at 7:49 am
  • Editorial Team
    Editorial Team added an answer Data structures are ways of storing stuff, just like you… May 13, 2026 at 7:49 am

Related Questions

I'm developing a dynamic html pop-up window (an absolute positioned div) using jQuery that
I'm a WPF n0ob and I'm struggling with selecting the appropriate control to get
When I log in on my dev machine in an ROR application, I should
Got some C# forms/controls that can be called up either from a C# control

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.