在C语言中连接数据库,通常使用的是数据库提供的客户端库。以下是一些常见数据库及其在C语言中连接的方法:
MySQL
1. 使用 `mysql.h` 和 `mysqlclient.h`。
2. 首先需要包含相应的头文件,并链接 `mysqlclient` 库。
```c
include
int main() {
MYSQL conn;
conn = mysql_init(NULL);
if (!mysql_real_connect(conn, "host", "user", "password", "database", 0, NULL, 0)) {
fprintf(stderr, "%sn", mysql_error(conn));
mysql_close(conn);
return 1;