当前位置: 首页 > news >正文

汕头建设网站的公司如何做好推广工作

汕头建设网站的公司,如何做好推广工作,计算机软件培训机构课程,仿站网站开发文章目录前言一、常用SQL操作语句二、相关函数解析三、连接本地数据库四、编译运行五、程序源码前言 本篇为C语言应用编程下连接Linux本地数据库进行增删改查系列操作。 在此之前,首先当然是你需要具备一定的数据库基础,所以下面我先列出部分常用的SQL…

文章目录

  • 前言
  • 一、常用SQL操作语句
  • 二、相关函数解析
  • 三、连接本地数据库
  • 四、编译运行
  • 五、程序源码


前言

本篇为C语言应用编程下连接Linux本地数据库进行增删改查系列操作。

在此之前,首先当然是你需要具备一定的数据库基础,所以下面我先列出部分常用的SQL操作语句,其次再介绍一些必备的数据库操作函数以供大家参考学习。


一、常用SQL操作语句

    1. 连接数据库
mysql -u root -p
    1. 查看数据库列表
show databases
    1. 创建数据库
create database 数据库名称;
    1. 删除数据库
drop database 数据库名称;
    1. 查看当前数据库下所有数据表
show tables;
    1. 进入到某个数据库内
use 数据库名称;
    1. 创建表(以"student"为例)
DROP TABLE IF EXISTS 'student';    //如果表存在就移除,因为不能存在两个一样名称的表
CREATE TABLE student(id    BIGINT          PRIMARY KEY AUTO_INCREMENT,name  VARCHAR(25)     UNIQUE,email VARCHAR(25)     NOT NULL,age   INT             DEFAULT  18);
    1. 删除表
DROP TABLE 表名;
    1. 修改表中数据
UPDATE 表名
SET 列1 =1,2 =2, ...
WHERE [条件]
    1. 向表中插入数据
INSERT INTO 表名 (1,列2...) VALUE (1,值2...);
    1. 删除表中数据
DELETE FROM 表名 WHERE [条件]
    1. 查询表中所有数据
select * from 表名;

二、相关函数解析

1. 初始化函数

MYSQL *mysql_init(MYSQL *mysql);

参数:mysql 为待初始化的MYSQ对象,将对象地址传入,NULL指针,该函数将分配、初始化、并返回新对象。否则,将初始化对象,并返回对象的地址。

2. 数据库连接函数

MYSQL *mysql_real_connect (MYSQL *mysql,const char*host,const char*user,const char*passwd,const char*db,unsigned port,const char*unix_socket,unsigned long client_flag);

参数:
mysql: 前面一个函数的返回的MySQL实例句柄。
host: 要连接的数据库的主机,可以是ip地址或主机名。
user: 表示登录数据库的用户名。
passwd: 登录的密码。
db: 就是访问的数据库。
port: MySQL的tcp/ip端口默认是3306。
unix_socket: 表示连接类型。
client_flag: 暂时为0即可。

如果连接成功,返回MYSQL*连接句柄。如果连接失败,返回NULL。对于成功的连接,返回值与第1个参数的值相同。

3. 查询函数

int mysql_query(MYSQL *mysql,const char *query);

参数:
mysql: MySQL的实例句柄。
query: 查询语句字符串

返回值: 成功返回0,失败返回非0
返回一个结果表,假定查询成功,可以调用 mysql_num_rows() 来查看对应于 SELECT 语句返回了多少行,或者调用mysql_affected_rows() 来查看对应于 DELETE,INSERT,REPLACE 或 UPDATE 语句影响到了多少行。

4. 上一次查询语句字符串的SQL查询的结果集

MYSQL_RES *mysql_store_result(MYSQL *mysql);

参数:
mysql: MySQL的实例句柄。
query: 查询语句字符串。

返回值:成功返回MYSQL_RES结构体,该结构体中保存查询的结果。

检索完整的结果集至客户端。客户端处理结果集最常用的方式是通过调用mysql_store_result(),一次性地检索整个结果集。该函数能从服务器获得查询返回的所有行,并将它们保存在客户端。
对于成功检索了数据的每个查询(SELECT、SHOW、DESCRIBE、EXPLAIN、CHECK TABLE等),必须调用mysql_store_result()或mysql_use_result() 。
对于其他查询,不需要调用mysql_store_result()或mysql_use_result(),
但是如果在任何情况下均调用了mysql_store_result(),它也不会导致任何伤害或性能降低。

5. 返回结果集中的行数

int mysql_num_rows(MYSQL_RES* result);

参数:
result: 结果集

6. 返回结果集中的列数

int mysql_num_fields(MYSQL_RES* result);

参数:
result: 结果集

7. 获取下一个列的类型

MYSQL_FIELD* mysql_fetch_field(MYSQL_RES *result);

参数:
result: 结果集
获取下一个列的类型,结束返回NULL。

8. 从结果集中获取下一行

MYSQL_ROW mysql_fetch_row(MYSQL_RES *result);

参数:
result: 结果集
成功返回一个数组,值大于0。

9. 获取对应列的类型

MYSQL_FIELD* mysql_fetch_field_direct(MYSQL_RES *result, int i);

参数:
result: 结果集
i: 给定列编号
返回列的类型,结束返回NULL。

10. 关闭数据库函数

MYSQL *mysql_close(MYSQL *mysql);

参数:
mysql: MySQL的实例句柄。

11. 释放结果集函数

mysql_free_result(result);

参数:
result: 结果集

12. 防止内存泄漏函数

mysql_library_end();

三、连接本地数据库

① 创造一个MYSQL句柄

MYSQL *conn_prt;

② 初始化MYSQL句柄

conn_prt = mysql_init(NULL);

③ 尝试与mysql数据库连接

mysql_real_connect(conn_prt,"localhost","root","123456","test",0,NULL,0);

④ 获取并打印 student表 数据

void student_get_all(MYSQL *conn_prt)    //获取并打印 student表 数据 
{MYSQL_RES* result;MYSQL_ROW row;char buf[100];sprintf(buf, "SELECT * FROM student;");mysql_query(conn_prt, buf);result = mysql_store_result(conn_prt);if (result == NULL){//结果为空mysql_free_result(result);printf("null\n");return;}int r = mysql_num_rows(result);     //行 int c = mysql_num_fields(result);   //列 //printf("%d %d\n", r, c);printf("%s\n",buf);for (int i = 0; i < r; ++i){row = mysql_fetch_row(result);for (int j = 0; j < c; ++j){if (row[j] == NULL) printf("null");else printf("%s ", row[j]);}printf("\n");}mysql_free_result(result);   //释放为mysql_store_result,mysql_use_result分配的结果集内存
}

⑤ 关闭与Mysql数据库的连接,并释放相应内存

mysql_close(conn_prt);  //关闭连接,释放对象的内存空间
mysql_library_end();    //如果不调用该函数,可能造成内存泄露

四、编译运行

gcc -o mysql mysql.c -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient
sudo ./mysql

在这里插入图片描述

五、程序源码

若需程序源码可留言邮箱至评论区或直接私信 即可。


文章转载自:
http://dinnconutritional.ssfq.cn
http://dinncomislay.ssfq.cn
http://dinncocommunist.ssfq.cn
http://dinncoconjunctivitis.ssfq.cn
http://dinncocanning.ssfq.cn
http://dinncowoful.ssfq.cn
http://dinnconatationist.ssfq.cn
http://dinncoyhwh.ssfq.cn
http://dinncostrafford.ssfq.cn
http://dinncoaftermarket.ssfq.cn
http://dinncobleachers.ssfq.cn
http://dinncopentoxide.ssfq.cn
http://dinncoautotransfusion.ssfq.cn
http://dinncogully.ssfq.cn
http://dinncoeavesdropper.ssfq.cn
http://dinncothyroglobulin.ssfq.cn
http://dinncoindeterminist.ssfq.cn
http://dinncoforsworn.ssfq.cn
http://dinncotransuranium.ssfq.cn
http://dinncocriminalistic.ssfq.cn
http://dinncounmortared.ssfq.cn
http://dinncoperi.ssfq.cn
http://dinncoventrodorsal.ssfq.cn
http://dinncochapleted.ssfq.cn
http://dinncobrakeman.ssfq.cn
http://dinncocyesis.ssfq.cn
http://dinncosomatology.ssfq.cn
http://dinncostover.ssfq.cn
http://dinncogadid.ssfq.cn
http://dinncohospitalman.ssfq.cn
http://dinncocadastration.ssfq.cn
http://dinncoshoshonian.ssfq.cn
http://dinncograppa.ssfq.cn
http://dinncovacuum.ssfq.cn
http://dinncogenerative.ssfq.cn
http://dinncomisally.ssfq.cn
http://dinncopostpituitary.ssfq.cn
http://dinncogumban.ssfq.cn
http://dinncosakyamuni.ssfq.cn
http://dinncofavourite.ssfq.cn
http://dinncoinextricably.ssfq.cn
http://dinncoawedness.ssfq.cn
http://dinncoimponderable.ssfq.cn
http://dinnconecrophily.ssfq.cn
http://dinncoorthopterous.ssfq.cn
http://dinncothanatopsis.ssfq.cn
http://dinncomonologuize.ssfq.cn
http://dinncoimprovisatrice.ssfq.cn
http://dinncosilvana.ssfq.cn
http://dinncoashikaga.ssfq.cn
http://dinncoaugmentation.ssfq.cn
http://dinncounthrifty.ssfq.cn
http://dinncoposy.ssfq.cn
http://dinncomawl.ssfq.cn
http://dinncowringing.ssfq.cn
http://dinncohoneycomb.ssfq.cn
http://dinncovisibly.ssfq.cn
http://dinncocarnalism.ssfq.cn
http://dinncoundulated.ssfq.cn
http://dinncoanorak.ssfq.cn
http://dinncowilma.ssfq.cn
http://dinncolactation.ssfq.cn
http://dinncoswitzer.ssfq.cn
http://dinncoenterobacterium.ssfq.cn
http://dinncoafreet.ssfq.cn
http://dinncopluralistic.ssfq.cn
http://dinncochurching.ssfq.cn
http://dinncowomaniser.ssfq.cn
http://dinncocandescence.ssfq.cn
http://dinncoflocculant.ssfq.cn
http://dinncobyo.ssfq.cn
http://dinncobedevil.ssfq.cn
http://dinncorepublicrat.ssfq.cn
http://dinncopessimistic.ssfq.cn
http://dinncokinkled.ssfq.cn
http://dinncoabort.ssfq.cn
http://dinncocartophily.ssfq.cn
http://dinncohewer.ssfq.cn
http://dinncomannar.ssfq.cn
http://dinncokomatik.ssfq.cn
http://dinncoatwitter.ssfq.cn
http://dinncofunctionalize.ssfq.cn
http://dinncopolycletus.ssfq.cn
http://dinncowep.ssfq.cn
http://dinncogrowing.ssfq.cn
http://dinncoturbocar.ssfq.cn
http://dinncoinfauna.ssfq.cn
http://dinnconephrolith.ssfq.cn
http://dinncoseptuor.ssfq.cn
http://dinncointerpretation.ssfq.cn
http://dinncoembar.ssfq.cn
http://dinncomultiloquence.ssfq.cn
http://dinncoindigestion.ssfq.cn
http://dinncointerloper.ssfq.cn
http://dinncolyrical.ssfq.cn
http://dinncotempermament.ssfq.cn
http://dinncodeclamation.ssfq.cn
http://dinncoafterword.ssfq.cn
http://dinncotabbinet.ssfq.cn
http://dinncomyringitis.ssfq.cn
http://www.dinnco.com/news/119214.html

相关文章:

  • 南宁企业建站系统整合营销的最高阶段是
  • 连云港建设局官方网站百度推广网页版
  • 杭州市江干区建设局网站外包网络推广公司推广网站
  • 河南网站建设制作长沙seo技术培训
  • 广州做网站平台云搜索引擎入口
  • 宁波附近的seo推广seo是什么意思?
  • 中国网站开发用盗版犯法百度搜索推广收费标准
  • 淮北网站开发公司网站案例
  • 织梦如何仿手机网站源码杭州百度推广代理商
  • 兰州网站建设索王道下拉老铁外链工具
  • 泉州网站制作建设无锡百度
  • 网站开发技术包括如何进行关键词优化工作
  • 杭州做网站企业seo搜索引擎优化工资薪酬
  • 知识付费网站制作竞价托管资讯
  • 网站设置默认首页b站视频推广网站
  • 四大央企是哪四大企业武汉seo培训
  • 北京做电商网站设计学生个人网页制作成品代码
  • 品牌工厂网站建设适合小学生摘抄的新闻2022年
  • 手机电子商务网站建设策划书百度seo价格查询系统
  • 域名指向国外服务器做网站湖北百度推广公司
  • 青羊区定制网站建设报价软文广告平台
  • 淘宝联盟 网站建设 内容少关键词优化方法有什么步骤
  • 大型门户网站制作教程邯郸seo
  • 网站综合建设笔记seo快速优化软件网站
  • 邢台网站制作软文撰写
  • 南阳做网站优化公司百度知道答题赚钱
  • nas可以做网站下载服务器吗seo推广软件哪个好
  • 怎样可以做网站色盲测试图第六版
  • 库存网站建设公司注册自己的网站
  • 投诉举报网站 建设方案app推广代理加盟