• 用户验证的C++小程序 mysql++


    前提:安装mysql 和mysql++、mysql++-devel

    程序:#include<iostream>
    #include "mysql++.h"
    #include <string>
    using namespace mysqlpp;
    using namespace std;
    int main()
    {       char  usrstr[30];
            bool  userexist=false;
            cout<<"Please input your username:";
            cin>>usrstr;

    //建立连接
            mysqlpp::Connection con(false);
            if(con.connect("test","localhost","root",""))

    // test is db name ,localhost is server host name 
            {
                    cout<<"success"<<endl;
                    mysqlpp::Query query=con.query("select username from userlist");
                    mysqlpp::StoreQueryResult res=query.store();
                    for (int i=0;i<res.num_rows();i++)
                    {
                    if (strcmp(usrstr,res[i][0])==0)
                            userexist=true;
                    }
                    if (userexist)
                            cout<<"Welcome "<<usrstr<<endl;
       }

    }

     编译连接:g++ -L /usr/lib/mysql -lmysqlclient -L /usr/lib -lmysqlpp -Ilib -I/usr/include/mysql -I/usr/include/mysql++ userlogin.cc -o userlogin.o

    ps:

    -Idir
      在你是用#i nclude"file"的时候,gcc/g++会先在当前目录查找你所制定的头文件,如果没有找到,他回到缺省的头文件目录找,如果使用-I制定了目录,他会先在你所制定的目录查找,然后再按常规的顺序去找.
      对于#i nclude<file>,gcc/g++会到-I制定的目录查找,查找不到,然后将到系统的缺省的头文件目录查找

    -Ldir
      制定编译的时候,搜索库的路径。比如你自己的库,可以用它制定目录,不然编译器将只在标准库的目录找。这个dir就是目录的名称。

    传递给会连接程序.

      -llibrary

  • 相关阅读:
    Hibernate,get()和load()区别
    Hibernate,Session方法使得java对象进入持久化状态;持久化对象特征
    Hibernate,Session清理缓存时间点
    frameset子窗口获取父窗口失败原因?
    struts2,实现Ajax异步通信
    struts2-json-plugin插件实现异步通信
    Hibernate,JPA注解@ManyToMany_JoinTable
    Hibernate,JPA注解@ManyToMany
    SparkStreaming操作Kafka
    DirectStream、Stream的区别-SparkStreaming源码分析02
  • 原文地址:https://www.cnblogs.com/jewell/p/2092629.html
Copyright © 2020-2023  润新知