linux实现登录操作,连接数据块

#include<stdio.h>
#include<mysql/mysql.h>
#include<string.h>
int main()
{
    //初始化数据库的句柄
    MYSQL *con = mysql_init(NULL);
    //连接数据库
    if(!(mysql_real_connect(con,"localhost","root","1","Stu",0,NULL,0)))
    {
        printf("连接失败\n");
        return -1;
    }
    //对数据库进行操作--倒入数据
    char buf[200]={0};
    char name[20],passwd[20];
    scanf("%s%s",name,passwd);
    getchar();
    sprintf(buf,"select passwd from stu where name ='%s'",name);
    mysql_real_query(con,buf,strlen(buf));


    //把查找的数据放入结构体中----对其操作的都要放在数组中
    MYSQL_RES* res = mysql_store_result(con);
    int rows = mysql_num_rows(res);
    int columns = mysql_num_fields(res);
    if(rows == 0)
    {
        printf("无数据\n");
        return -1;
    }

    //登陆的功能:
    char **a = mysql_fetch_row(res);//找到了一行中一个数据
    if(strcmp(passwd,a[0])==0)
    {
        printf("登陆成功\n");
    }
    else
    {
        printf("密码错误\n");
    }

    mysql_close(con);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值