PDO连接到其他服务器上的SQLite服务器 [英] PDO connect to SQLite server on different server

查看:111
本文介绍了PDO连接到其他服务器上的SQLite服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的SQLite数据库,需要从其他服务器读取/写入.

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

说数据库存储在这里: http://www.abc.com/data/data .sqlite 而且我正在使用PHP从 http://www.xyz.com

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";

它确实有效. 我知道数据库URL和数据库本身是正确的. 那么访问跨服务器是否有限制?有人知道要解决这个问题吗?

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?

非常感谢.

推荐答案

没有像"SQLite服务器"这样的东西.它仅以文件形式存在.
但是HTTP协议中没有文件,只有URI.
因此,这是必不可少的不兼容性.

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.

要进行远程通话,您有3种选择

To be able to do remote calls you have 3 choices

  1. 只是开个玩笑:在每次执行SELECT查询之前先在本地下载文件,然后在更新后将其上传回来
  2. 建立一些代理脚本,以接收查询并返回json.
  3. 让自己成为真正的数据库服务器.
  4. 或者只是更改项目体系结构以消除对远程访问的需求.

这篇关于PDO连接到其他服务器上的SQLite服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆