1

The code below is an attempt to connect more than one database using PHP PDO and SQLite. No matter what I tried, it does not accept the select test1.table1. If I remove the database name the select works; so how do I reference more than one database in the select?

<?php

  // connect to SQLite3 database 
  $query = "test1.sqlite3";
  $db = new PDO("sqlite:$query"); 

  // connect to second db
  $query = "attach test2.sqlite3";
  $db->query($query); 

  $query  = "Select * FROM test1.table1 ";
  $result = $db->query($query);
  $rows   = $result->fetchall(PDO::FETCH_ASSOC);

  foreach ($rows as $row) {
    echo "<pre>".print_r($row)."</pre>";
  }  

?>
1
  • 1
    Please note that the ATTACH statement requires an AS clause; your second connection did not work. Commented Jul 21, 2014 at 7:24

1 Answer 1

1

The first database you connect to (test1.sqlite3 in your case) is always called main, regardless of the actual filename. Try SELECT * FROM main.table1.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.