国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

think-orm插件

v2.1.6 版本
2025-05-27 版本更新時間
42826 安裝
9 star

簡介

think-orm是ThinkPHP官方的一個基于PHP和PDO的數(shù)據(jù)庫中間層和ORM類庫。

webman/think-orm 是一個自動化安裝 topthink/think-orm 的插件。它做了三個事情
1、安裝ThinkPHP官方的原生topthink/think-orm組件
2、webman項目里自動增加配置文件config/thinkorm.php
3、設(shè)置定時器定時向數(shù)據(jù)庫發(fā)送select 1語句,避免數(shù)據(jù)庫連接超時間空閑被數(shù)據(jù)庫服務(wù)端斷開。

安裝

composer require -W webman/think-orm

安裝后將自動生成 config/thinkorm.php 數(shù)據(jù)庫配置文件,開發(fā)者需要根據(jù)實際情況手動更改數(shù)據(jù)庫配置。

提示
如果出現(xiàn)無法安裝,可能是由于使用了composer代理導致,可運行命令composer config -g --unset repos.packagist去掉代理再次嘗試。

使用

<?php
namespace app\controller;

use support\Request;
use think\facade\Db;

class Foo
{
  public function get(Request $request)
  {
      $user = Db::table('user')->where('uid', '>', 1)->find();
      return json($user);
  }
}

模型

ThinkOrm模型繼承think\Model,類似如下

<?php
namespace app\model;

use think\Model;

class User extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'user';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $pk = 'id';

}

你也使用以下命令創(chuàng)建基于thinkorm的模型

php webman make:model 表名

提示
此命令需要安裝webman/console,安裝命令為composer require webman/console ^1.2.13

注意
make:model 命令如果檢測到主項目使用了illuminate/database,會優(yōu)先創(chuàng)建基于illuminate/database的模型文件,而不是thinkorm的,這時可以通過附加一個參數(shù)tp來強制生成think-orm的模型,命令類似 php webman make:model 表名 tp (如果不生效請升級webman/console)

更多請參考topthink/think-orm文檔

贊助商