| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Lib;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Capsule\Manager as DB;
- use datainf\lib\GlobConfigs;
- /**
- * model基类
- */
- class ModelBase extends Model
- {
- static protected $db = null;
- public $timestamps = false;
- protected $table = '';
- function getSql()
- {
- return $this->getConnection()->getQueryLog();
- }
- static function beginTransaction()
- {
- return self::$db->getConnection()->getPdo()->beginTransaction();
- }
- static function getDB()
- {
- return self::$db;
- }
- static function rollBack()
- {
- return self::$db->getConnection()->getPdo()->rollBack();
- }
- static function commit()
- {
- return self::$db->getConnection()->getPdo()->commit();
- }
- public static function init()
- {
- $conf = GlobConfigs::getKey('pgsql');
- self::$db = new DB();
- self::$db->addConnection($conf);
- self::$db->setAsGlobal();
- self::$db->bootEloquent();
- return self::$db;
- }
- public static function close()
- {
- if (self::$db) {
- self::$db->getConnection()->disconnect();
- self::$db = null;
- }
- }
- }
|