Skip to content

Commit

Permalink
1.优化部分数据操作
Browse files Browse the repository at this point in the history
  • Loading branch information
xcg340122 committed Sep 18, 2018
1 parent 110abb4 commit 119c101
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
19 changes: 13 additions & 6 deletions Framework/Library/Process/Drive/Db/Mysqli.php
Expand Up @@ -73,6 +73,12 @@ class Mysqli implements DbInterfaces
*/
protected $database = '';

/**
* 表前缀
* @var string
*/
protected $tabprefix = '';

/**
* 获取错误信息
* @return string
Expand All @@ -96,6 +102,9 @@ public function connect($config = [])
if ($this->link != null) {
$this->database = $config['database'];
mysqli_query($this->link, 'set names ' . $config['char']);
if(!empty($config['tabprefix'])){
$this->tabprefix = $config['tabprefix'];
}
return $this->link;
} else {
\Framework\App::$app->get('LogicExceptions')->readErrorFile([
Expand All @@ -108,6 +117,7 @@ public function connect($config = [])
/**
* 操作多数据库连接
* @param $link
* @return $this
*/
public function setlink($link)
{
Expand Down Expand Up @@ -148,7 +158,7 @@ public function find()

/**
* debug
* @return array
* @return bool|mixed
*/
public function debug()
{
Expand All @@ -172,7 +182,7 @@ public function total()
public function table($tabName = '')
{
if (!empty($tabName)) {
$this->tableName = '`' . $tabName . '`';
$this->tableName = '`' . $this->tabprefix . $tabName . '`';
$this->getTableInfo();
return $this;
} else {
Expand Down Expand Up @@ -231,10 +241,7 @@ public function select($qryArray = [])
if (empty($field)) $field = ' * ';

if (isset($qryArray['join'])) {
$join .= ' ' . is_array($qryArray['join']) ? implode(' ', $qryArray['join']) : $qryArray['join'];
if (empty($join)) {
$join = ' ' . $join;
}
$join = is_array($qryArray['join']) ? ' '.implode(' ', $qryArray['join']) : ' '.$qryArray['join'];
}
if (isset($qryArray['where'])) {
$where = $this->structureWhere($qryArray['where']);
Expand Down
23 changes: 17 additions & 6 deletions Framework/Library/Process/Drive/Db/PDO.php
Expand Up @@ -16,38 +16,43 @@ class Pdo implements DbInterfaces
* @var string
*/
public $dbErrorMsg = 'SQL IN WRONG: ';

/**
* 获取方式
* @var int
*/
public $fetchMethod = \PDO::FETCH_OBJ;

/**
* 实例对象
* @var
*/
protected $pdo;

/**
* 结果集
* @var bool
*/
protected $result = false;

/**
* 影响条数
* @var
*/
protected $total;

/**
* 操作表名
* @var null
*/
protected $tableName = NULL;

/**
* debug
* @var array
*/
protected $queryDebug = [];


/**
* 数据主键
* @var string
Expand All @@ -72,6 +77,12 @@ class Pdo implements DbInterfaces
*/
protected $database = '';

/**
* 表前缀
* @var string
*/
protected $tabprefix = '';

/**
* 获取异常信息
* @return mixed
Expand Down Expand Up @@ -101,6 +112,9 @@ public function connect($config = [])

$this->pdo = new \PDO($dsn, $config['username'], $config['password'], $opt);
$this->database = $config['database'];
if(!empty($config['tabprefix'])){
$this->tabprefix = $config['tabprefix'];
}
return $this->pdo;
} catch (\PDOException $ex) {
exit($this->dbErrorMsg . $ex->getMessage());
Expand Down Expand Up @@ -252,7 +266,7 @@ private function handleres($sql, $iserror = false, $ex = [])
public function table($tableName = '')
{
if (!empty($tableName)) {
$this->tableName = '`' . $tableName . '`';
$this->tableName = '`' . $this->tabprefix . $tableName . '`';
$this->getTableInfo();
return $this;
} else {
Expand Down Expand Up @@ -318,10 +332,7 @@ public function select($qryArray = [])
if (empty($field)) $field = ' * ';

if (isset($qryArray['join'])) {
$join .= is_array($qryArray['join']) ? implode(' ', $qryArray['join']) : $qryArray['join'];
if (empty($join)) {
$join = ' ' . $join;
}
$join = is_array($qryArray['join']) ? ' '.implode(' ', $qryArray['join']) : ' '.$qryArray['join'];
}
if (isset($qryArray['where'])) {
$where = $this->structureWhere($qryArray['where']);
Expand Down
1 change: 1 addition & 0 deletions Framework/frame.php
Expand Up @@ -120,6 +120,7 @@ public function run()
if (Running::$runMode == 'cli') Visit::setCliParam();
$object = Visit::mergeParam();
$function = Visit::getfunction();
Running::setconstant();
$app = new $object();
if (method_exists($app, $function)) {
$this->get('ReturnHandle')->Output($app->$function());
Expand Down
3 changes: 3 additions & 0 deletions Project/Common/Config/Db.cfg.php
Expand Up @@ -25,6 +25,9 @@
/** 数据库名称 */
'database' => 'test',

/** 数据表前缀 */
'tabprefix' => '',

/** 数据库编码 */
'char' => 'utf8',

Expand Down
4 changes: 2 additions & 2 deletions Project/Model/UserModel.class.php
Expand Up @@ -4,8 +4,8 @@

/**
* 数据模型类演示
* Class IndexModel
* @package Model\Home
* Class UserModel
* @package App\Model
*/
class UserModel
{
Expand Down

0 comments on commit 119c101

Please sign in to comment.