From b8d6128259fb256c129d21ece712d5d66fdaa7a5 Mon Sep 17 00:00:00 2001 From: aixiao Date: Tue, 25 Mar 2025 21:19:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SERVER/hc-12/mysql.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SERVER/hc-12/mysql.c b/SERVER/hc-12/mysql.c index 8942a41..910afdd 100644 --- a/SERVER/hc-12/mysql.c +++ b/SERVER/hc-12/mysql.c @@ -11,6 +11,14 @@ int _mysql(char *sql, char *MYSQL_HOST, char *MYSQL_PORT_, char *MYSQL_USRT, cha } int result = 0; + int timeout = 7; // 设置超时时间(秒) + + // 设置连接超时时间 + mysql_options(&mysql, MYSQL_OPT_CONNECT_TIMEOUT, &timeout); + + // 设置读、写超时时间(影响查询) + mysql_options(&mysql, MYSQL_OPT_READ_TIMEOUT, &timeout); + mysql_options(&mysql, MYSQL_OPT_WRITE_TIMEOUT, &timeout); if (mysql_real_connect(&mysql, MYSQL_HOST, MYSQL_USRT, MYSQL_PASSWORD, "mysql", atoi(MYSQL_PORT_), NULL, 0)) { if (0 != mysql_set_character_set(&mysql, "utf8")) {