Siôn Roberts
Siôn Roberts

Reputation: 11

PDO connect to SQLite server on different server

I have a very simple SQLite database that I need to read/write to from a different server.

Say the database is stored here : http://www.abc.com/data/data.sqlite And I'm using PHP to access it from http://www.xyz.com

So my first attempt was the following:

$dbpath = "http://www.abc.com/data/data.sqlite";
$dbconn = "sqlite:$dbpath";
$db = new PDO($dbconn)

No good, I get the following:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [14] unable to open database file'.........PDO->__construct('sqlite:http://w...') #1 {main} thrown

If try and copy the database onto the same server I'm accessing from:

$dbpath = "http://www.xyz.com/data/data.sqlite";
$dbconn = "sqlite:$dbpath";
$db = new PDO($dbconn)

I get the same message. It's only when I give it a relative path on the same server:

$dbpath = "../data/data.sqlite";

That it actually works. I know the database URLs and database itself are correct. So is there a limitation to accessing cross-servers? Anyone know out to solve this issue?

Thanks a lot.

Upvotes: 1

Views: 2107

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157828

There are no such thing like 'SQLite server'. It exists only in a form of a file.
But there are no files in the HTTP protocol, but URIs only.
So, this is essential incompatibility.

To be able to do remote calls you have 3 choices

  1. Only as a joke: download the file locally before each SELECT query and upload it back after updates
  2. Establish some proxy script, to recieve a query and to return json.
  3. Get yourself a real database server.
  4. Or just change the project architecture to eliminate the need of remote access.

Upvotes: 2

Related Questions