不像Oracle, MYSQL数据库并不支持嵌入式SQL语言。但是提供了功能强大的C,C++支持API,其中c语言的API在参考手册的第25部分,独立于这个3000多页的参考手册之外的另外部分的MySQL++是用于C++的MySQL API。Warren Young负责该项目。要想了解更多信息,请访问http://www.mysql.com/products/mysql++/。当然mysql似乎最为广泛的应用是个php脚本语言一起,apache,一起用做网站的后台数据库服务程序,这个做过好多。同时我是一个C程序员,碰到什么总是想用c试试,这几天忙着准备军转考试,刚好有点闲暇时间,顺便把c和mysql数据库的访问再复习一遍。运行环境是SunOS x4100 5.10 Generic_118855-33 i86pc i386 i86pc;编译器是gcc,外加Llibmysqlclient库。
- #include <stdio.h>
- #include <string.h>
- #include <mysql.h>
- #include <stdlib.h>
- main()
- {
- MYSQL *conn;
- MYSQL_RES *res;
- MYSQL_ROW row;
- char *server = "mysql";
- char *user = "huzia";
- char *password = "cjrIwo"; /* */
- char *database = "huzia";
- conn = mysql_init(NULL);
-
- /* Connect to database */
- if (!mysql_real_connect(conn, server,
- user, password, database, 0, NULL, 0)) {
- fprintf(stderr, "%s
", mysql_error(conn));
- exit(1);
- }
-
- /* send SQL query */
- if (mysql_query(conn, "show tables")) {
- fprintf(stderr, "%s
", mysql_error(conn));
- exit(1);
- }
-
- res = mysql_use_result(conn);
- /* output table name */
- printf("MySQL Tables in mysql database:
");
- while ((row = mysql_fetch_row(res)) != NULL)
- printf("%s
", row[0]);
-
- /* close connection */
- mysql_free_result(res);
- mysql_close(conn);
- }
运行成功。Linux 下的Oracle的基本操作RedHat Enterprise Linux 5.5安装Oracle 11g 找不到WFMLRSVCApp.ear相关资讯 C语言 MySQL教程
- 最受欢迎编程语言又是谁?C语言居 (今 08:08)
- C语言背后的运行机制 (03月06日)
- 30分钟带你快速入门MySQL教程 (02月03日)
| - C是2016年最流行语言 (07月28日)
- 轻松学C语言(图解版)高清晰扫描 (02月25日)
- MySQL教程:关于checkpoint机制 (01月24日)
|
本文评论 查看全部评论 (0)