Download the PHP package xuey490/database without Composer

On this page you can find all versions of the php package xuey490/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package database

安装

介绍: 利用工厂接口类整合Eloquent 和 ThinkORM 的Model和DB的操作,实现两者的无缝切换

初始化

现在你的调用方式更纯粹,不再依赖全局环境:

使用范例

根据上面的使用示例,下面补充几个使用表名,模型类来操作数据库的例子,结合illuminate和thinkphp的特性,比如查询(limit,排序,条件查询,分组,统计等),分页,删除,修改更新,事物回滚等

核心提示:虽然通过 DatabaseFactory 统一了“获取数据库操作对象”的入口(make),但获取到的对象(Query Builder 或 Model)依然是各自 ORM 的原生对象。

因此,ThinkPHP ORM 和 Illuminate (Laravel) ORM 在具体的方法调用上(如 get() vs select(), orderBy() vs order())是有区别的。

以下是结合这两种 ORM 特性的详细对比使用示例。


0. 初始化准备

为了演示,假设我们已经通过工厂初始化了数据库。


1. 查询构造器 (Table 模式)

当你传入字符串(表名)时,工厂返回的是查询构造器。

场景:复杂条件、排序、分页、限制数量


2. 模型模式 (Class 模式)

当你传入模型类名时,工厂返回模型实例。

假设定义了 User 模型:

场景:新增、修改、查询单条


3. 高级查询:分组与统计

语法上有细微差别:Laravel 使用 groupBy,ThinkPHP 使用 group。


4. 分页 (Pagination)

这是最常用的功能,两者返回的分页对象不同,但调用方式类似。


5. 删除操作 (Delete)


6. 事务处理 (Transactions)

这是重构后最需要注意的地方。 由于工厂已经将 DB 库初始化为全局可用(Think 的 Db::setConfig 和 laravelORM 的 Capsule::setAsGlobal),我们建议直接使用各自 ORM 的静态方法来管理事务,因为事务通常是全局的,而不是绑定在某个模型实例上的。

总结:如何屏蔽差异?

由于两个 ORM 语法(get vs select, orderBy vs order)差异客观存在,如果你想在业务代码中完全无感切换,通常有几种做法:

  1. Repository 模式(推荐):在 Factory 之上再封装一层 Repository,比如 UserRepository->findAll(),在 Repository 内部根据驱动类型去写 if-else。
  2. 只使用交集语法:但这很难,因为连最基础的查询结束符都不一样。
  3. 拥抱特定 ORM:工厂模式主要解决了初始化和多项目复用的问题。在实际业务中,如果你决定用 Eloquent,就统一按 Eloquent 写;工厂的作用是让你在新开项目想切回 ThinkORM 时,只需改配置和少量业务逻辑,而不需要重写底层连接代码。

All versions of database with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/bus Version 13.30.*
illuminate/collections Version 13.30.*
illuminate/conditionable Version 13.30.*
illuminate/container Version 13.30.*
illuminate/contracts Version 13.30.*
illuminate/database Version 13.30.*
illuminate/events Version 13.30.*
illuminate/macroable Version 13.30.*
illuminate/pipeline Version 13.30.*
illuminate/reflection Version 13.30.*
illuminate/support Version 13.30.*
topthink/think-orm Version ^4.0.51
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package xuey490/database contains the following files

Loading the files please wait ...