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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:37:04+00:00 2026-06-13T01:37:04+00:00

Context Playing with two of Feeddemon’s SQLite databases, tags.fdb and feeds.fdb , I created

  • 0

Context

Playing with two of Feeddemon’s SQLite databases, tags.fdb and feeds.fdb, I created this working raw query (tested using Firefox’ handy addon SQLite Manager):

SELECT tbl_tags.tag_name, feeds.tbl_posts.link
FROM tbl_tags
INNER JOIN feeds.tbl_posts
ON tbl_tags.fd_postid=feeds.tbl_posts.fd_postid
ORDER BY tbl_tags.tag_name

It queries both Feeddemon’s tags.fdb primarily and attached feeds.fdb database files (using SQLite’s feature ATTACH feeds.fdb AS feeds). It lists all tagged posts with their tag names and hyperlinks. As you can see, the database content is related by fd_postid.

An example to visualize what happens:

tags.fdb‘s tbl_tags table content:

fd_postid tag_name
1         rainbow
2         orange
5         green

feeds.fdb‘s tbl_posts table content:

fd_postid link
1         google.com
2         stackoverflow.com
3         microsoft.com
4         slashdot.org
5         techcrunch.com

Query results, ordered by tag_name:

green    techcrunch.com    
orange   stackoverflow.com
rainbow  google.com

Question

How do I implement this single inner join query to cover multiple related databases, using PDO in PHP?

Connecting to two databases in PDO also creates two objects:

$db1 = new PDO('sqlite:tags.fdb');
$db2 = new PDO('sqlite:feeds.fdb');

But if I want to query, I have to specify a single object:

$result = $db1->query('SELECT * FROM sometable');

So how do I bridge the gap and use one query to target both databases?

Or can I use SQLite’s ATTACH database AS alias feature directly in PDO? If so, how? But this would probably be considered bad practice, right? Since PDO is intended to be database non-specific.

I think this user was looking for the same thing, in the end, but never really got to the point of a working code sample:

How do you join two PDO objects in the same foreach loop?

Note: When answering please consider the fact that I’m a front-end/graphics guy, who just started learning PHP/PDO/SQLite since about two months ago. The question is probably above my experience level. I’m surprised I managed to get the raw query working. But I’m learning…

  • 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-13T01:37:05+00:00Added an answer on June 13, 2026 at 1:37 am

    To access multiple databases from one query in SQLite, you have to ATTACH them.

    With PDO, it works in same way as you would execute any other SQL command; you just specify a different file name (and directory, if needed):

    $db = new PDO('sqlite:tags.db');
    $db->exec('ATTACH \'feeds.db\' as feeds');
    $result = $db->query('SELECT tbl_tags.tag_name, feeds.tbl_posts.link ...');
    

    While PDO is intended to be mostly independent of the actual database, you cannot avoid specifying the sqlite: when opening the database, and the actual SQL dialect you can use always depends on the database. For practical purposes, the ATTACH command is logically part of opening the database, and feeds.tbl_posts is just a table name.

    Note: SQLite searches for table names in all attached databases, so you can omit the database name for unique table names.

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

Sidebar

Related Questions

Playing round with Timers. Context: a winforms with two labels. I would like to
I'm playing around with authentication and authorization to prepare for some task. I've created
I have created a radio group which contains two buttons, I can select one
I've been playing around with this for some time now and am hoping that
Context Sometimes, I like reading code on paper rather than on screen (so I
Context (doc count) ------------------------- clojure.core/count ([coll]) Returns the number of items in the collection.
Context I am aware of http://closure-library.googlecode.com/svn/trunk/closure/goog/demos/editor/equationeditor.html# However, when I try it, it does not
Context Clojure Agents are NOT sent new values. They are sent a function which
Context I am trying to understand the internals of a big, hairy JavaScript library.
Context: In Lua, it's trivial and very cheap (4kb of memory) to create 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.