构建 ORM - mysqli 与常规 SQL 与 PDO
我一直在寻找一个非常轻量级的 PHP ORM 库,并且遇到了一些不错的选择。不幸的是,大多数选择都需要某种形式的 配置,例如向类中添加更多字段以及其中的许多字段 不太直观。
我不想使用框架,但更喜欢 Q&D 的 ORM 原型。
不管怎样,我开始构建自己的 PHP ORM 库,称为 SORM(简单 ORM)。它很大程度上处于阿尔法状态。 查看代码和示例,
您可以在https://github.com/teraom/sorm
我将不胜感激如果您可以提供一些反馈或指示 如何进行、需要改变的事情等 我有兴趣使用 mysqli 进行数据库查询,特别是准备好的 语句,以避免SQL注入。
有没有办法在常规 PHP - SQL 中使用准备好的语句 功能?或者通过其他方式防止SQL注入? https://www.php.net/manual/en/ref.mysql。 php
安装PHP时默认安装了mysqli吗? (PHP 5.2 和 上)
我对 PDO 知之甚少。 PHP 5.2及以上版本默认安装PDO吗? PDO 也会出现吗?
谢谢, 巴拉德
I have been looking for a very light weight PHP ORM library and I ran across a few good choices. Unfortunately, most choices require some form of
configuration, e.g. adding more fields to the class and many of them
are not so intuitive.
I do not want to use a framework, but prefer just the ORM for Q&D
prototypes.
Anyway, I started building my own PHP ORM library called SORM (Simple ORM). It is very much in alpha state. You can checkout the code and examples at
https://github.com/teraom/sorm
I would appreciate if you can provide some feedback or directions on
how to proceed, things to change etc.
I am interested in using mysqli for database queries, specifically for prepared
statements, so as to avoid SQL injection.
Is there a way to use prepared statements with regular PHP - SQL
functions? Or prevent SQL injection by other means?
https://www.php.net/manual/en/ref.mysql.phpIs mysqli installed by default when you install PHP? (PHP 5.2 and
above)I know very little about PDO. Is PDO installed by default in PHP 5.2 and above? Does PDO come into picture too?
Thanks,
Bharad
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当常规功能支持时。过时的“mysql”扩展不提供此功能。其他一些则这样做,例如 PostgreSQL 的。
这是无法回答的,因为它取决于 PHP 的编译方式(如果是自定义安装),或者是否通过包管理器安装。如果它是通过包管理器安装的,那么所有数据库支持很可能都在可选附加包中。但是,如果启用了 mysql 支持,则“mysqli”扩展应该可用。
与之前的答案相同——这取决于 PHP 的安装方式。它在编译时默认启用,但根据包管理的不同,它可能不可用。
一般来说,您可以依赖 PDO 在大多数情况下都可用。如果不是,则要么是系统管理员的监督,要么是白痴经理故意决定禁用它。
许多现代 PHP 都是假设 PDO 存在而构建的。为 PDO 和 mysqli 制作适配器并没有太大的坏处,因为两者都具有大体相似的功能集。请注意
bind_param< 的奇怪方式/code>
有效 - 它需要一次调用所有要绑定的内容,通过引用。这往往会让人们失去兴趣。
另一种选择:不要直接在 PDO 之上构建,而是在另一个包装器之上构建。我不想让您了解所有 Inception,但请看一下 Zend_Db< /a>.是的,我知道你不想使用框架,但无论如何还是看一下它。它具有适用于各种 PDO 风格、mysqli、Oracle 和 DB2 的适配器。它也非常全面,并且查询构建器(Zend_Db_Select)非常方便。
该领域还有很多其他选项,例如 好旧的 PEAR MDB2,它使用 < a href="http://pear.php.net/manual/en/package.database.mdb2.intro-execute.php" rel="nofollow">模拟伪造准备好的语句和占位符。
Only when supported by the regular functions. The decrepit "mysql" extension does not provide this functionality. Some others do, like the one for PostgreSQL.
This is not answerable, as it depends on how PHP was compiled (if it's a custom installation), or whether it was installed via a package manager. If it was installed through a package manager, then it's very likely that all database support might be in an optional add-on package. However, if mysql support in general is enabled, the "mysqli" extension should be available.
Same answer as before -- it depends on how PHP was installed. It's enabled by default when compiling, but it might not be available depending on package management.
In general, you can rely on PDO being available most of the time. When it's not, it's either going to be oversight on behalf of the sysadmin, or an intentional decision to disable it by an idiot manager.
A lot of modern PHP is built assuming PDO will be there. There's not too much harm in making adapters for both PDO and mysqli, as both have generally similar feature sets. Just watch out for the weird, weird way that
bind_param
works -- it expects one call with all of the things to bind, by reference. This tends to turn people off.Another option: Instead of building on top of PDO directly, build on top of another wrapper. I don't want to get all Inception on you, but take a peek at Zend_Db. Yes, I know you don't want to use a framework, but take a look at it anyway. It has adapters for the various PDO flavors, mysqli, Oracle, and DB2. It's also quite comprehensive, and the query builder (Zend_Db_Select) is pretty handy.
There are lots of other options in this area, like good old PEAR MDB2, which uses emulation to fake prepared statements and placeholders.