Files
youlegames/codes/agent/game/dlweb/api/lib/1.0/models/Db.php
2026-03-15 01:27:05 +08:00

104 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
class Db
{
/**
* 数据查询实例
* @var null
*/
public static $Db = null;
private static function _init()
{
if(!self::$Db)
self::$Db = new BaseMethod();
}
/**
* 查询方法,返回单条数据
* @param $sql
* @param array $arr
* @return mixed
* @throws \Exception
*/
public static function query($sql, $arr = [])
{
self::_init();
$result = self::$Db->PDO_Request($sql, $arr);
if(!self::$Db->PDO_IsDone())
throw new Exception(self::$Db->GetErrorInfo(), 101);
if(isset($result[0]))
return $result[0];
return false;
}
/**
* 查询方法,返回多条数据
* @param $sql
* @param $arr
* @return array
* @throws \Exception
*/
public static function queryAll($sql, $arr = [])
{
self::_init();
$result = self::$Db->PDO_Request($sql, $arr);
if(!self::$Db->PDO_IsDone())
throw new Exception(self::$Db->GetErrorInfo(), 102);
return $result;
}
/**
* 只执行sql语句不反回结果
* @param $sql
* @param array $arr
* @return bool
* @throws \Exception
*/
public static function execute($sql, $arr = [])
{
self::_init();
$ret = self::$Db->PDO_Execute($sql, $arr);
if(!$ret || !self::$Db->PDO_IsDone())
throw new \Exception(self::$Db->GetErrorInfo(), 103);
return true;
}
/**
* 开启事务
*/
public static function beginTransaction()
{
self::_init();
self::$Db->PDO_BeginTransaction();
}
/**
* 提交一个事务
*/
public static function commit()
{
self::$Db->PDO_Commit();
}
/**
* 回滚一个事务
*/
public static function rollBack()
{
self::$Db->PDO_Rollback();
}
}