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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:38:52+00:00 2026-06-05T02:38:52+00:00

I am writing a cronjob which would transfer data from one table, process it

  • 0

I am writing a cronjob which would transfer data from one table, process it and then apply it to a web application. I have 2 seperate database connections for this. At the moment, the connection credentials are the same except it’s different databases, but going live, it will be entirely seperated.

The issue is I am creating a connection then assigning it in my class to $this->staging and the other is called $this->production. I use mysql_ping to ensure that both connections are working.

What appears to happen is that when it does a query, it disregards the connection identifier ($this->staging example) and tries to do a query on the last of the 2 connections created.

I use the connection identifier within the query:

 // Connection:

 $this->staging = $this->mysql($config['staging']);
 $this->production = $this->mysql($config['production']);

 $sql = "SELECT * FROM TABLE";
 $query = mysql_query($sql,$this->staging);

 // Returns an unknown table in database defined in $this->production.

I return the mysql_connect as the $this->mysql() method, and not the mysql_select_db(). If I try returning mysql_select_db() mysql_ping does not work.

Here is the mysql() method:

// connect(): Connect to a database (MySQL):

private function mysql($cred) {
    $connect = mysql_connect($cred['server'],$cred['username'],$cred['password']);
    if($connect) {
        $db = mysql_select_db($cred['database']);
        if($db) {
            return $connect;
        } else {
            $this->informer("[FATAL]","Could not make a mysql database connection on server ".$_SERVER['SERVER_ADDR']." for database: ".$cred['database']);
        }
    } else {
        $this->informer("[FATAL]","The database credentials appears to be wrong. ".$_SERVER['SERVER_ADDR']." for the mysql database: ".$cred['database']);
    }
}
  • 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-05T02:38:54+00:00Added an answer on June 5, 2026 at 2:38 am

    The problem happens because you are connecting to the same MySql server, when you connect to the staging (second connection) the PHP returns the same connection created for the production and don’t create a new one, to force the PHP to create a new one you should change the “mysql_connect” call to be like this:

     $connect = mysql_connect($cred['server'],$cred['username'],$cred['password'], true);
    

    this will force the PHP to start a new connection.

    Ref: http://www.php.net/mysql_connect

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

Sidebar

Related Questions

i have a design issue regarding sending user data from a mobile phone app
I have got a Rails app running which displays data that is generated by
I'm running a cronjob which needs to write data to a cache. I wanted
I'm writing a small Python script which will periodically pull information from a 3rd
I have a simple enough web application. I want to measure for any day
Writing my first Android app. Thought I would start with a Corporate Directory application.
I'm writing a backup script I intend to execute in a cronjob every night.
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
Writing a .NET DLL how do I find Application.ProductName ? EDIT: Obviously, importing Windows.Forms
Writing my first C# application...never touched the language before and not much of a

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.