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);