feat: 本次提交更新内容如下

php有问题,覆盖下
This commit is contained in:
笔记本里的永平
2025-07-07 14:52:56 +08:00
parent c29fbd1bbb
commit c9a3aaab58
338 changed files with 70315 additions and 12737 deletions

View File

@@ -13,6 +13,7 @@ namespace think\db\connector;
use PDO;
use think\db\Connection;
use think\db\Query;
/**
* Sqlsrv数据库驱动
@@ -23,28 +24,33 @@ class Sqlsrv extends Connection
protected $params = [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::ATTR_STRINGIFY_FETCHES => false,
];
protected $builder = '\\think\\db\\builder\\Sqlsrv';
/**
* 解析pdo连接的dsn信息
* @access protected
* @param array $config 连接信息
* @param array $config 连接信息
* @return string
*/
protected function parseDsn($config)
{
$dsn = 'sqlsrv:Database=' . $config['database'] . ';Server=' . $config['hostname'];
if (!empty($config['hostport'])) {
$dsn .= ',' . $config['hostport'];
}
return $dsn;
}
/**
* 取得数据表的字段信息
* @access public
* @param string $tableName
* @param string $tableName
* @return array
*/
public function getFields($tableName)
@@ -64,6 +70,7 @@ class Sqlsrv extends Connection
$pdo = $this->query($sql, [], false, true);
$result = $pdo->fetchAll(PDO::FETCH_ASSOC);
$info = [];
if ($result) {
foreach ($result as $key => $val) {
$val = array_change_key_case($val);
@@ -77,23 +84,30 @@ class Sqlsrv extends Connection
];
}
}
$sql = "SELECT column_name FROM information_schema.key_column_usage WHERE table_name='$tableName'";
// 调试开始
$this->debug(true);
$pdo = $this->linkID->query($sql);
// 调试结束
$this->debug(false, $sql);
$result = $pdo->fetch(PDO::FETCH_ASSOC);
if ($result) {
$info[$result['column_name']]['primary'] = true;
}
return $this->fieldCase($info);
}
/**
* 取得数据表的字段信息
* @access public
* @param string $dbName
* @param string $dbName
* @return array
*/
public function getTables($dbName = '')
@@ -106,16 +120,112 @@ class Sqlsrv extends Connection
$pdo = $this->query($sql, [], false, true);
$result = $pdo->fetchAll(PDO::FETCH_ASSOC);
$info = [];
foreach ($result as $key => $val) {
$info[$key] = current($val);
}
return $info;
}
/**
* 得到某个列的数组
* @access public
* @param Query $query 查询对象
* @param string $field 字段名 多个字段用逗号分隔
* @param string $key 索引
* @return array
*/
public function column(Query $query, $field, $key = '')
{
$options = $query->getOptions();
if (empty($options['fetch_sql']) && !empty($options['cache'])) {
// 判断查询缓存
$cache = $options['cache'];
$guid = is_string($cache['key']) ? $cache['key'] : $this->getCacheKey($query, $field);
$result = Container::get('cache')->get($guid);
if (false !== $result) {
return $result;
}
}
if (isset($options['field'])) {
$query->removeOption('field');
}
if (is_null($field)) {
$field = '*';
} elseif ($key && '*' != $field) {
$field = $key . ',' . $field;
}
if (is_string($field)) {
$field = array_map('trim', explode(',', $field));
}
$query->setOption('field', $field);
// 生成查询SQL
$sql = $this->builder->select($query);
$bind = $query->getBind();
if (!empty($options['fetch_sql'])) {
// 获取实际执行的SQL语句
return $this->getRealSql($sql, $bind);
}
// 执行查询操作
$pdo = $this->query($sql, $bind, $options['master'], true);
if (1 == $pdo->columnCount()) {
$result = $pdo->fetchAll(PDO::FETCH_COLUMN);
} else {
$resultSet = $pdo->fetchAll(PDO::FETCH_ASSOC);
if ('*' == $field && $key) {
$result = array_column($resultSet, null, $key);
} elseif ($resultSet) {
$fields = array_keys($resultSet[0]);
$count = count($fields);
$key1 = array_shift($fields);
$key2 = $fields ? array_shift($fields) : '';
$key = $key ?: $key1;
if (strpos($key, '.')) {
list($alias, $key) = explode('.', $key);
}
if (3 == $count) {
$column = $key2;
} elseif ($count < 3) {
$column = $key1;
} else {
$column = null;
}
$result = array_column($resultSet, $column, $key);
} else {
$result = [];
}
}
if (isset($cache) && isset($guid)) {
// 缓存数据
$this->cacheData($guid, $result, $cache);
}
return $result;
}
/**
* SQL性能分析
* @access protected
* @param string $sql
* @param string $sql
* @return array
*/
protected function getExplain($sql)