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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:57:05+00:00 2026-05-23T11:57:05+00:00

I am using sphinx for a site search and it works great but now

  • 0

I am using sphinx for a site search and it works great but now I am trying to connect to 2 mysql databases with the same exact structure and db2 is a continuance of db1 so all info should flow smoothly. I can easily get the results by switching the db name in the code but how can I select both at once?

here is some code im using

$CONF['sphinx_host'] = 'localhost';
$CONF['sphinx_port'] = 9312;
$CONF['mysql_host'] = "localhost";
$CONF['mysql_username'] = "user";
$CONF['mysql_password'] = "password";
$CONF['mysql_database'] = "db1";
$CONF['sphinx_index'] = "index index2";


$db = mysql_connect($CONF['mysql_host'],$CONF['mysql_username'],$CONF['mysql_password']) or die("ERROR: unable to connect to database");
mysql_select_db($CONF['mysql_database'], $db) or die("ERROR: unable to select database");


$sql = str_replace('$ids',implode(',',$ids),$CONF['mysql_query']);
$result = mysql_query($sql) or die($CONF['debug']?("ERROR: mysql query failed: ".mysql_error()):"ERROR: Please try later");

This code works fine if i enter a single mysql db into $CONF['mysql_database'] = "db1"; but I need to select from db1 and db2. Does anyone know how I can achieve this? Also I did not post the query because I don’t think it is very useful it is just a simple select query and I am sure you get the idea.

  • 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-23T11:57:06+00:00Added an answer on May 23, 2026 at 11:57 am

    If the databases are hosted on the same server, you can simply pick one arbitrarily in your call to mysql_select_db() and then qualify all table names in your SQL queries with a databasename. prefix. You can even mix and match tables from both databases in a single query. eg.

    select h.lastname, h.firstname, p.petname
        from db1.humans as h
        left outer join db2.pets as p on p.human_id = h.id;
    

    If you don’t need to write queries that involve both databases, you can simply call mysql_select_db() again each time you need to switch databases.

    If the databases are hosted on different servers, you will need 2 separate calls to mysql_connect(). In this case, make sure to pass the optional $link parameter to all mysql_ functions because the default behavior is to simply use the most recent connection, which can lead to all kinds of bugs. Since each database will have a separate connection, you will not be able to run individual queries that access both databases.

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

Sidebar

Related Questions

I have sphinx installed for my search engine, and it works great, but now
I'm thinking about using Sphinx as a search engine for my site. But since
I'm trying to start using Sphinx to document some little projects of mine, but
When using the PHP Sphinx client this works: SphinxClient::query ('*', 'index1'); But when I
I'm trying to get sphinx search to return excerpts of matched documents. I'm using
I'm using Sphinx to search MySQL. One of the results Sphinx returns for a
I am using Sphinx Search . It's working fine for me except one problem:
Created using Sphinx 0.6.5. I know Python's documentation uses reStructuredText , but it has
I am using Sphinx Search on a website to keep track of various table
I asked before for a simple solution to my problem (using sphinx search service)

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.