基础配置与底层修改
This commit is contained in:
@@ -136,7 +136,15 @@ class Fastphp
|
||||
//配置数据库信息
|
||||
public function setDbConfig()
|
||||
{
|
||||
if (isset($this->config['db'])) {
|
||||
$formal_origin = $this->config['formal_origin']; //跨域访问的时候才会存在此字段
|
||||
$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
|
||||
if (in_array($origin, $formal_origin)) {
|
||||
define('DB_HOST', $this->config['formal_db']['host']);
|
||||
define('DB_PORT', $this->config['formal_db']['port']);
|
||||
define('DB_NAME', $this->config['formal_db']['dbname']);
|
||||
define('DB_USER', $this->config['formal_db']['username']);
|
||||
define('DB_PASS', $this->config['formal_db']['password']);
|
||||
} else {
|
||||
define('DB_HOST', $this->config['db']['host']);
|
||||
define('DB_PORT', $this->config['db']['port']);
|
||||
define('DB_NAME', $this->config['db']['dbname']);
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* @Descripttion:
|
||||
* @version:
|
||||
* @Author: kangkang
|
||||
* @Date: 2020-09-30 17:32:46
|
||||
* @LastEditors: kangkang
|
||||
* @LastEditTime: 2020-11-12 19:17:36
|
||||
*/
|
||||
|
||||
namespace fastphp\base;
|
||||
|
||||
@@ -30,8 +38,12 @@ class Controller
|
||||
$getPayload=$jwt->verifyToken($token);
|
||||
|
||||
} else {
|
||||
$jwt = new Jwt('etor_yh_lzh_20f_2020_YES');
|
||||
$getPayload=$jwt->verifyToken($_SERVER['HTTP_TOKEN']);
|
||||
if(isset($_SERVER['HTTP_TOKEN'])){
|
||||
$jwt = new Jwt('etor_yh_lzh_20f_2020_YES');
|
||||
$getPayload=$jwt->verifyToken($_SERVER['HTTP_TOKEN']);
|
||||
} else {
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2020-09-30 17:32:46
|
||||
* @LastEditTime: 2020-10-26 10:33:22
|
||||
* @LastEditTime: 2020-11-16 16:09:31
|
||||
* @LastEditors: kangkang
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: /phptest/fastphp/base/Model.php
|
||||
@@ -40,6 +40,16 @@ class Model extends Sql
|
||||
return $this->field('count(1) as count')->where($where)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 获取所有的列表
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
*/
|
||||
public function getList($where = [],$fields = '*', $order = 'id desc')
|
||||
{
|
||||
return $this->field($fields)->where($where)->order($order)->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照页数获取数据
|
||||
* @param $fields 'id,count(1)...'
|
||||
@@ -59,16 +69,17 @@ class Model extends Sql
|
||||
*/
|
||||
public function getOne($where = [], $fields = '*')
|
||||
{
|
||||
return $this->field($fields)->where($where)->limit('1')->fetch();
|
||||
return $this->field($fields)->where($where)->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: 获取最新一条数据
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
*/
|
||||
public function getNewOne($fields = '*'){
|
||||
return $this->field($fields)->order('id desc')->limit(1)->fetch();
|
||||
public function getNewOne($fields = '*')
|
||||
{
|
||||
return $this->field($fields)->order('id desc')->fetch();
|
||||
}
|
||||
/**
|
||||
* @description: 更新一条数据
|
||||
|
||||
@@ -30,7 +30,7 @@ class Sql
|
||||
{
|
||||
$this->filter .= '';
|
||||
if ($where) {
|
||||
if(!strpos($this->filter,'WHERE') !== false){
|
||||
if (!strpos($this->filter, 'WHERE') !== false) {
|
||||
$this->filter .= ' WHERE ';
|
||||
} else {
|
||||
$this->filter .= ' AND ';
|
||||
@@ -39,14 +39,15 @@ class Sql
|
||||
$this->filter .= $where;
|
||||
} else {
|
||||
$flag = true;
|
||||
$ins = ['in', 'IN', 'not in', 'NOT IN'];
|
||||
foreach ($where as $key => $value) {
|
||||
if ($flag) {
|
||||
$flag = false;
|
||||
if (is_array($value)) {
|
||||
if($value[0] == 'in'){
|
||||
$this->filter .= ' `' . $key . '` ' . $value[0] . '('.implode(',',$value[1]).')';
|
||||
if (in_array($value[0], $ins)) {
|
||||
$this->filter .= ' `' . $key . '` ' . $value[0] . '(' . implode(',', $value[1]) . ')';
|
||||
} else {
|
||||
$param_key = $this->paramIsExit($key,$this->param);
|
||||
$param_key = $this->paramIsExit($key, $this->param);
|
||||
$this->filter .= ' `' . $key . '` ' . $value[0] . ' :' . $param_key;
|
||||
$this->param[$param_key] = $value[1];
|
||||
}
|
||||
@@ -56,10 +57,10 @@ class Sql
|
||||
}
|
||||
} else {
|
||||
if (is_array($value)) {
|
||||
if($value[0] == 'in'){
|
||||
$this->filter .= ' AND `' . $key . '` ' . $value[0] . '('.implode(',',$value[1]).')';
|
||||
if (in_array($value[0], $ins)) {
|
||||
$this->filter .= ' AND `' . $key . '` ' . $value[0] . '(' . implode(',', $value[1]) . ')';
|
||||
} else {
|
||||
$param_key = $this->paramIsExit($key,$this->param);
|
||||
$param_key = $this->paramIsExit($key, $this->param);
|
||||
$this->filter .= ' AND `' . $key . '` ' . $value[0] . ' :' . $param_key;
|
||||
$this->param[$param_key] = $value[1];
|
||||
}
|
||||
@@ -74,12 +75,13 @@ class Sql
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function paramIsExit($key,$param){
|
||||
if(!isset($param[$key])){
|
||||
public function paramIsExit($key, $param)
|
||||
{
|
||||
if (!isset($param[$key])) {
|
||||
return $key;
|
||||
} else {
|
||||
$key .= $key;
|
||||
return $this->paramIsExit($key,$param);
|
||||
return $this->paramIsExit($key, $param);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,11 +105,11 @@ class Sql
|
||||
* @return $this
|
||||
* $group=['sex','name']
|
||||
*/
|
||||
public function group($group = [])
|
||||
public function group($group = [], $having = '')
|
||||
{
|
||||
if ($group) {
|
||||
$this->filter .= ' GROUP BY ';
|
||||
$this->filter .= ' ' . implode(' ,', $group) . ' ';
|
||||
$this->filter .= ' ' . implode(' ,', $group) . ' ' . $having . ' ';
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
@@ -159,7 +161,7 @@ class Sql
|
||||
*/
|
||||
public function fetch()
|
||||
{
|
||||
$sql = sprintf('SELECT %s FROM `%s` %s', $this->field, $this->table, $this->filter);
|
||||
$sql = sprintf('SELECT %s FROM `%s` %s LIMIT 1', $this->field, $this->table, $this->filter);
|
||||
$this->filter = '';
|
||||
$sth = Db::pdo()->prepare($sql);
|
||||
$sth = $this->formatParam($sth, $this->param);
|
||||
@@ -176,7 +178,7 @@ class Sql
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$sql = sprintf('DELETE FROM `%s` %s', $this->table, $this->filter);
|
||||
$sql = sprintf('DELETE FROM `%s` %s LIMIT 1', $this->table, $this->filter);
|
||||
$this->filter = '';
|
||||
$sth = Db::pdo()->prepare($sql);
|
||||
$sth = $this->formatParam($sth, $this->param);
|
||||
@@ -225,7 +227,7 @@ class Sql
|
||||
$sql = sprintf('UPDATE `%s` SET %s %s', $this->table, $this->formatUpdate($data), $this->filter);
|
||||
$this->filter = '';
|
||||
$sth = Db::pdo()->prepare($sql);
|
||||
$sth = $this->formatParam($sth, $data);
|
||||
$sth = $this->formatUpdateParam($sth, $data);
|
||||
$sth = $this->formatParam($sth, $this->param);
|
||||
$this->param = [];
|
||||
$sth->execute();
|
||||
@@ -248,6 +250,20 @@ class Sql
|
||||
return $sth;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定具体变量值update
|
||||
* @param PDOStatement $sth
|
||||
* @param array $params
|
||||
* @return PDOStatement
|
||||
*/
|
||||
public function formatUpdateParam(PDOStatement $sth, $params = [])
|
||||
{
|
||||
foreach ($params as $param => &$value) {
|
||||
$param = ':' . ltrim($param, ':').'update';
|
||||
$sth->bindParam($param, $value);
|
||||
}
|
||||
return $sth;
|
||||
}
|
||||
/**
|
||||
* 将数组转化为插入格式的sql语句
|
||||
* @param $data
|
||||
@@ -295,8 +311,8 @@ class Sql
|
||||
{
|
||||
$fields = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$fields[] = sprintf('`%s`=:%s', $key, $key);
|
||||
$this->param[$key] = $value;
|
||||
$fields[] = sprintf('`%s`=:%s', $key, $key.'update');
|
||||
$this->param[$key.'update'] = $value;
|
||||
}
|
||||
return implode(',', $fields);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @Author: kangkang
|
||||
* @Date: 2020-09-30 17:32:46
|
||||
* @LastEditors: kangkang
|
||||
* @LastEditTime: 2020-10-16 11:14:25
|
||||
* @LastEditTime: 2020-11-14 10:35:30
|
||||
*/
|
||||
/**
|
||||
* 浏览器友好的变量输出
|
||||
|
||||
Reference in New Issue
Block a user