有人知道不使用 PDO 的优秀 PHP ORM 吗?

发布于 2024-10-12 17:32:29 字数 712 浏览 3 评论 0原文

我正在为一所大型大学校园的一个部门构建一个 Web 应用程序,该应用程序最终将在企业服务器上运行(我宽松地使用术语“企业”)。

问题在于管理员拒绝编译和启用除 SQLite 之外的任何 PDO 扩展。不过,他们确实启用了 mysql 和 mysqli,所以这并不是完全损失。

那么这里有人知道 PHP 的一个好的 ORM 不依赖 PDO 作为它的主要引擎吗?

我已经研究过 Doctrine 和 Propel(都是优秀的框架),但不知道如何从它们内部剥离 PDO。

编辑:这是我从服务器管理员那里得到的响应:

肖恩

我们曾多次尝试构建包含 PDO 扩展的 PHP,但均未成功。我们没有成功的原因很复杂,但基本上源于这样一个事实:Web 环境最初是由一些静态编译的数据库驱动程序库和一些动态编译的数据库驱动程序库建立的,这种混合导致 PDO 大声抱怨。这样做的原因是 PHP 5.x 早期版本中的一个错误,该错误现在已不再是问题(或至少不再是问题),但切换很困难,因为更改需要修改 php.ini。 ini 文件,并且由于每个站点(包括[服务器编辑]上的站点)都有自己的 php.ini(总共大约 22,000 个文件,其中许多文件被用户修改),因此很难推出该更改(并且不进行更改会导致在具有未更新文件的帐户提供的页面上出现错误[我不记得它们是否是致命的])。

I'm building a webapp for a department on a large college campus that will eventually be run on the enterprise servers ( I use the term 'enterprise' loosely ).

The problem is that the admins have refused to compile and enable any PDO extension other than SQLite. They do have mysql and mysqli enabled though, so it's not a total loss.

So does anybody out here know of a good ORM for PHP that does NOT rely on PDO as it's main engine?

I've already looked at Doctrine and Propel (both excellent frameworks), though could not figure out how to rip PDO out from inside them.

Edit: Here is the response I've gotten from the admins on the server:

Sean,

We have tried, unsuccessfully, several times to build PHP with the PDO extension included. The reason we haven't been successful is complicated, but basically stems from the fact that the web envoronment was originally set up with some database driver libraries compiled staticly and others compiled dynamically, the mix causing PDO to complain loudly. The reason things were were done this way was due to a bug in early versions of PHP 5.x that is no longer an issue today (or at least less of one), but switching is difficult because the change would require modifications to php.ini files and, since every site (including sites on [server redacted]) has its own php.ini (roughly 22,000 files total, many of which are modified by users) it is very difficult to push out that change (and not making the change causes errors [I don't recall if they are fatal or not] on pages served from accounts with non-updated files).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风挽心 2024-10-19 17:32:29

我认为每个现代 ORM 都依赖 PDO,因为它是标准数据库驱动程序。

如果您启用了 MySQLi 扩展,那么您应该能够编写自己的扩展PDO(IIRC MySQLi 支持 PDO 所做的一切)。

if (extension_loaded('pdo_mysql') == false) {
    class PDO {
        protected $connection;

        public function __construct($dsn, $username = null, $password = null, array $driver_options = array()) {
            $this->connection = new MySQLi(...);
        }
    }

    class PDOStatement { ... }
    class PDOException extends RuntimeException { ... }
}

您必须实现整个 PDO API,但至少它可以工作。

I suppose that every modern ORM relies on PDO as it's a standard database driver.

If you have MySQLi extension enabled then you should be able to write your own PDO (IIRC MySQLi supports everything that PDO does).

if (extension_loaded('pdo_mysql') == false) {
    class PDO {
        protected $connection;

        public function __construct($dsn, $username = null, $password = null, array $driver_options = array()) {
            $this->connection = new MySQLi(...);
        }
    }

    class PDOStatement { ... }
    class PDOException extends RuntimeException { ... }
}

You'll have to implement whole PDO API but at least it will works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文