- 4
- 0
- 约1.08万字
- 约 13页
- 2016-10-18 发布于贵州
- 举报
Linux-MSQL数据库与Linux程序开发
《Linux程序设计》实验指导(三)
MYSQL数据库与Linux程序开发
实验三:MYSQL数据库与Linux程序开发(综合性、4学时)
本项实验综合了MYSQL与Linux程序开发、多模块软件编译与链接过程等章节的知识点。根据实验指导书的要求和步骤,完成相应的程序开发及多模块软件编译与链接过程,并在Linux环境下,完成程序开发及软件剖析。
一、实验目的:
1)掌握MYSQL数据库命令与应用编程。
2)了解Linux多模块软件编译与链接过程。
3)熟悉Linux下软件剖析与度量工具的使用。
二、实验内容
在你的Linux环境中安装MYSQL数据库系统。记录安装步骤和命令过程。
在Ubuntu12.04终端输入sudo apt-get install mysql-server
按提示输入Y确认安装
为使用数据库的用户创建密码,安装完成
编辑教材第298页select4.c程序,记录编译命令和运行结果。
//select4.c
#include stdlib.h
#include stdio.h
#include mysql.h
MYSQL my_connection;
MYSQL_RES *res_ptr;
MYSQL_ROW sqlrow;
void display_header();
void display_row();
int main(int argc,char *argv[])
{
int res;
int first_row =1;
mysql_init(my_connection);
if(mysql_real_connect(my_connection,localhost,rick,
123123,foo,0,NULL,0))
{
printf(Connection success!\n);
res=mysql_query(my_connection,SELECT childno,fname,age FROM children WHERE age5);
if(res){
fprintf(stderr,SELECT error:%s\n,mysql_error(my_connection)); }
else{
res_ptr = mysql_use_result(my_connection);
if(res_ptr)
{
while((sqlrow=mysql_fetch_row(res_ptr)))
{
if(first_row)
{
display_header();
first_row=0;
}
display_row();
}
if(mysql_errno(my_connection))
{
fprintf(stderr,Retrive error:%s\n,
mysql_error(my_connection));
}
mysql_free_result(res_ptr);
}}
mysql_close(my_connection);
}
else
{
fprintf(stderr,Connection failed\n);
if(mysql_errno(my_connection))
{
fprintf(stderr,Connection error %d: %s\n,
mysql_errno(my_connection),
mysql_error(my_connection));
}
}
return EXIT_SUCCESS;
}
void display_header()
{
MYSQL_FIELD *field_ptr;
printf(Column details:\n);
while((field_ptr = mysql_fetch_field(res_ptr)) != NULL)
{
printf(\t Name:%s\n,field_ptr-name);
printf(\t Type:);
if(IS_NUM(field_ptr-type))
{
printf(Numeric field\n);
}
else
{
switch(field_ptr-type){
case FIELD_TYPE_VAR_STRING:
printf(VARCHAR\n);
break;
case FIELD_TYPE_LONG:
printf(LONG\n
您可能关注的文档
最近下载
- 平凡的世界读书分享.ppt VIP
- 药物化学习题仉文升主编).pdf VIP
- 2025年山东济南高三一模数学试卷及答案.pdf VIP
- 2025年辽宁省委党校在职研究生招生考试(政治理论)历年参考题库含答案详解.docx VIP
- 保险双录标准话术.pptx
- 2025年辽宁省委党校在职研究生招生考试(法学)历年参考题库含答案详解.docx VIP
- 江苏省南通市2025年中考语文试卷(附答案解析).doc VIP
- 《人工智能在机械设计制造及其自动化中的实践》8900字.docx VIP
- 普传(POWTRAN)变频器PI500变频器使用说明书.pdf
- 最新部编版一年级数学下册教案(全册)表格式二次备课.doc VIP
原创力文档

文档评论(0)