(5).主程序(main.cpp)源码
 
#include"include/dbhelper.h"
#include"include/fields.h"
#include<iostream>
#define SIZE 50

int main(int argc,char **argv)
{
        char user[SIZE];
        char pass[SIZE];
        char host[SIZE];
        unsigned int port=3306;
        if(argc<2)
        {
                //不带参数登陆localhost:3306
                cout<<"输入用户名:";
                cin.get(user,SIZE).get();
                cout<<"输入密码:";
                cin.get(pass,SIZE);
                strcpy(host,"localhost");
        }
        else if(argc==2)
        {       //输入了主机 端口号默认为3306
                cout<<"输入用户名:";
                cin.get(user,SIZE).get();
                cout<<"输入密码:";
                cin.get(pass,SIZE);
                strcpy(host,argv[1]);
        }
        else
        {
                //输入了主机,端口号
                cout<<"输入用户名:";
                cin.get(user,SIZE).get();
                cout<<"输入密码:";
                cin.get(pass,SIZE);
                strcpy(host,argv[1]);
                port=atoi(argv[2]);
        }

        Fields conf=Fields(user,pass,port,host);
        DbHelper db(conf);
        if(db.getIsConn())
        {
                while(1)
                {
                        cout<<"输入SQL命令:(quit)退出\n";
                        string sql;
                        getline(cin,sql);
                        if(sql=="quit") break;
                        char *realsql=new char[sql.size()+1];
                        strcpy(realsql,sql.c_str());
                        if(db.execSQL(realsql))
                        {
                                db.showField();
                                cout<<db<<endl;
                        }
                        else
                        {
                                cout<<"执行语句:"<<sql<<"失败\n";
                        }
                        delete [] realsql;
                }
                cout<<"Bye!\n";
        }
        else
        {
                cout<<"连接失败:\n";
                cout<<"连接信息如下:\n\n";
                cout<<db.getConnArg()<<endl;
        }
        return 0;
}
 
好了,源码都完成了
接下来
(1).使用ls -Rl 命令查看结构
(2).编译
     进入源码目录
     执行
    g++ main.cpp dbhelper.cpp fields.cpp $(/usr/local/lnmp/mysql/bin/mysql_config --libs --cflags)
    上面命令执行完后会在当前目录中生成一个可执行文件 a.out
(3).运行
     ./a.out
    会提示输入用户名和密码 (输入你的mysql服务器连接的用户名和密码)
    成功连接后就能执行SQL命令了。
 
程序功能还很少,以后慢慢完善。