From 010a5b3271e36b2e354e804c9d78a6dfd0cddaec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=B1=95=E9=B9=8F?= Date: Sun, 15 Jun 2025 22:20:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor(database):=20=E5=B0=86SQL=20Server?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E4=BB=8Esqlsrv=E6=94=B9=E4=B8=BAFreeTDS?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改数据库连接方式以使用mssql扩展替代sqlsrv扩展,适配FreeTDS配置 更新相关查询和错误处理逻辑,确保功能一致性 --- E3_ycsys.php | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/E3_ycsys.php b/E3_ycsys.php index 4d96b23..a137858 100644 --- a/E3_ycsys.php +++ b/E3_ycsys.php @@ -1,19 +1,22 @@ "your_database", - "Uid" => "your_username", - "PWD" => "your_password" -); -// 检查 sqlsrv 扩展是否已加载 -if (!extension_loaded('sqlsrv')) { - die('SQLSRV 扩展未加载,请检查 PHP 配置。'); -} -$conn = sqlsrv_connect($serverName, $connectionOptions); +// 连接SQL Server数据库(FreeTDS方式) +$server = 'localhost'; +$database = 'your_database'; +$username = 'your_username'; +$password = 'your_password'; +// 检查mssql扩展是否已加载 +if (!function_exists('mssql_connect')) { + die('mssql 扩展未加载,请检查PHP配置并安装FreeTDS'); +} + +$conn = mssql_connect($server, $username, $password); if (!$conn) { - die(print_r(sqlsrv_errors(), true)); + die('无法连接数据库: ' . mssql_get_last_message()); +} + +if (!mssql_select_db($database, $conn)) { + die('无法选择数据库: ' . mssql_get_last_message()); } // 处理开关操作 @@ -22,19 +25,26 @@ if (isset($_GET['action']) && isset($_GET['id'])) { $status = $_GET['action'] == 'enable' ? 1 : 0; // 更新状态 - $sql = "UPDATE features SET status = ? WHERE id = ?"; - $params = array($status, $id); - $stmt = sqlsrv_query($conn, $sql, $params); + $sql = "UPDATE features SET status = $status WHERE id = '$id'"; + $result = mssql_query($sql, $conn); + if (!$result) { + die('更新失败: ' . mssql_get_last_message()); + } // 记录日志 - $logSql = "INSERT INTO operation_logs (feature_id, action, operation_time) VALUES (?, ?, GETDATE())"; - $logParams = array($id, $_GET['action']); - sqlsrv_query($conn, $logSql, $logParams); + $logSql = "INSERT INTO operation_logs (feature_id, action, operation_time) VALUES ('$id', '{$_GET['action']}', GETDATE())"; + $logResult = mssql_query($logSql, $conn); + if (!$logResult) { + die('日志记录失败: ' . mssql_get_last_message()); + } } // 查询功能列表 $sql = "SELECT id, name, description, status FROM features"; -$stmt = sqlsrv_query($conn, $sql); +$stmt = mssql_query($sql, $conn); +if (!$stmt) { + die('查询失败: ' . mssql_get_last_message()); +} // 微信HTML5页面 header('Content-Type: text/html; charset=utf-8'); @@ -81,5 +91,5 @@ header('Content-Type: text/html; charset=utf-8'); \ No newline at end of file