From 5f2d336807ec7efb2624c44b0f7c3be103d0bb9f Mon Sep 17 00:00:00 2001 From: flykhan Date: Wed, 20 Sep 2023 16:37:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/db.c | 23 +++++++++++++++++++++++ router/db.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/router/db.c b/router/db.c index 162aa36..76bd79c 100644 --- a/router/db.c +++ b/router/db.c @@ -87,6 +87,29 @@ int insert(const char *sql, MYSQL_BIND *params) return ret; // 返回是影响的行数 } +int delete(const char *sql, MYSQL_BIND *params) +{ + MYSQL_STMT *stmt = mysql_stmt_init(conn_db); + mysql_stmt_prepare(stmt, sql, strlen(sql)); + + if (params != NULL) + { + if (mysql_stmt_bind_param(stmt, params)) // 11)错误 0)成功 + { + mysql_stmt_close(stmt); + return -1; + } + } + if (mysql_stmt_execute(stmt) != 0) + { + mysql_stmt_close(stmt); + return -1; + } + int ret = mysql_stmt_fetch(stmt); + mysql_stmt_close(stmt); + return ret; // 返回是影响的行数 +} + int close_mysql() { if (conn_db != NULL) diff --git a/router/db.h b/router/db.h index 8ac2b3f..065f0f2 100644 --- a/router/db.h +++ b/router/db.h @@ -18,5 +18,8 @@ extern int result_rows(const char *sql); // 插入 extern int insert(const char *sql, MYSQL_BIND *params); +extern int delete(const char *sql, MYSQL_BIND *params); + + // 更新 extern int update(const char *sql, MYSQL_BIND *params);