问题描述
我正在尝试使用 C 脚本连接到 MariaDB 数据库,但找不到必要的文档.我安装了 libmariadbclient-dev,但找不到任何随附的文档,例如手册页.here 有基本描述和有限的文档,但是文档仅包括功能描述.事实是,尽管搜索了各种谷歌结果,我什至不知道要导入什么才能让它工作,更不用说如何使用它了.有没有关于如何在 C 中使用 MariaDB 数据库的指南或文档?
I'm trying to connect to a MariaDB database in a C script and I can't find the necessary documentation. I installed libmariadbclient-dev, but I couldn't find any accompanying documentation such as a man page. There's a basic description and limited documentation here, but the documentation only includes descriptions of functions. The fact is, despite having scoured all sorts of Google results, I don't even know what to import to get this to work, much less how to use it. Is there any guide or documentation on how to use a MariaDB database in C?
推荐答案
这里是:http://dev.mysql.com/doc/refman/5.5/en/c-api-function-overview.html
另一个:http://zetcode.com/db/mysqlc/
你可以编译一个最小的测试,比如
You can compile a minimal test like
#include <my_global.h>
#include <mysql.h>
int main(int argc, char **argv)
{
MYSQL *con = mysql_init(NULL);
if (con == NULL)
{
fprintf(stderr, "%s
", mysql_error(con));
exit(1);
}
if (mysql_real_connect(con, "localhost", "root", "root_pswd",
NULL, 0, NULL, 0) == NULL)
{
fprintf(stderr, "%s
", mysql_error(con));
mysql_close(con);
exit(1);
}
if (mysql_query(con, "CREATE DATABASE testdb"))
{
fprintf(stderr, "%s
", mysql_error(con));
mysql_close(con);
exit(1);
}
mysql_close(con);
exit(0);
}
使用
gcc -o mysql-test mysql-test.c $(mysql_config --libs)
这篇关于在 C 中使用 MariaDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!