mysql_stm参数绑定快速查询
来源:互联网 发布:ntp服务器软件 编辑:程序博客网 时间:2024/04/27 18:26
#include <stdio.h>#include <mysql/mysql.h>#include <stdlib.h>#include <string.h>int main(void){ MYSQL *conn; conn=mysql_init(NULL); if(!mysql_real_connect(conn,"localhost","root","",NULL,0,NULL,0)) { printf("连接失败%s,%d",mysql_error(conn),mysql_errno(conn)); return EXIT_FAILURE; } mysql_set_character_set(conn,"utf8"); mysql_query(conn,"use hes"); MYSQL_STMT *stmt;//定义一个预处理声明变量 stmt=mysql_stmt_init(conn); //初始化 char *str="select * from t4 where id>?"; /*先将不变的这部分发给数据库*/ mysql_stmt_prepare(stmt,str,strlen(str)); /*处理变动的那部分*/ /*定义变量保存输入的值*/ int id=0; char name[30]={0}; float sum=0; float sumcomp=0; printf("请输入金额比较值:\n"); scanf("%f",&sumcomp); MYSQL_BIND bind[4]; /*创建用来绑定参数的变量*/ bzero(bind,sizeof(bind)); //用0填充 /*第一个结果,整型数*/ bind[0].buffer=&id; bind[0].buffer_length=sizeof(id); bind[0].buffer_type=MYSQL_TYPE_LONG;//参数类型 /*第二个结果,字符串*/ bind[1].buffer=name; bind[1].buffer_length=sizeof(name); bind[1].buffer_type=MYSQL_TYPE_STRING; //参数类型 /*第三个结果,浮点型*/ bind[2].buffer=∑ bind[2].buffer_length=sizeof(sum); bind[2].buffer_type=MYSQL_TYPE_FLOAT; /*第四个参数,浮点型*/ bind[3].buffer=&sumcomp; bind[3].buffer_length=sizeof(sumcomp); bind[3].buffer_type=MYSQL_TYPE_FLOAT; /*将bind数组和预处理声明stmt绑定 实际是告诉服务器,这三个参数和某个固定部分"select * from t8"是对应的*/ mysql_stmt_bind_result(stmt,bind); mysql_stmt_bind_param(stmt,&bind[3]); /*将参数发给服务器*/ mysql_stmt_execute(stmt); while(mysql_stmt_fetch(stmt)!=MYSQL_NO_DATA) { printf("%d\t %s\t%.2f\n",id,name,sum); } //这里我们只需要改变要查询的条件,就可以完成类似的操作 printf("请输入金额比较值:\n"); scanf("%f",&sumcomp); mysql_stmt_execute(stmt); while(mysql_stmt_fetch(stmt)!=MYSQL_NO_DATA) { printf("%d\t %s\t%.2f\n",id,name,sum); } mysql_stmt_close(stmt); mysql_close(conn);}
阅读全文
0 0
- mysql_stm参数绑定快速查询
- hibernate查询之参数绑定
- hibernate_HQL查询的参数绑定
- 【转载】hibernate查询参数绑定
- 【转载】hibernate查询参数绑定
- HQL查询的参数绑定
- hibernate HQL查询的参数绑定
- Hql查询条件的参数绑定
- hibernate--HQL查询语句参数绑定
- Hql查询条件的参数绑定
- Hql查询条件的参数绑定
- hibernate)HQL查询的参数绑定(转)
- HQL 动态查询时参数绑定
- hibernate HQL查询的参数绑定
- hibernate HQL查询的参数绑定
- hibernate HQL查询的参数绑定
- hibernate HQL查询的参数绑定
- hibernate HQL查询几种参数绑定
- python中的一点小知识与库(3)
- Initializing 'Object' *__strong' with an expression of incompatible type 'id <Object> _Nullable
- Mac 外接机械键盘alt用不了
- 匹配所有连续子串
- python-配置国内下载镜像
- mysql_stm参数绑定快速查询
- 解决Maven依赖包下载慢--阿里云让你飞
- Redis 数据库入门指南
- win7系统uboot模式下tftp升级失败的原因之一
- zoj_最少点支配
- Dubbo——消费端启动过程分析
- RabbitMQ可靠确认模式的java封装及示例
- CentOS7搭建LNMP(Linux+Nginx+MySQL+PHP) 环境
- intellij+scala+maven+git