数据库操作函数增加数据删除操作

This commit is contained in:
flykhan 2023-09-20 16:37:44 +08:00
parent 7a0a6e0a29
commit 5f2d336807
2 changed files with 26 additions and 0 deletions

View File

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

View File

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