古之成大事者,不唯有超世之才,亦唯有堅(jiān)韌不拔之志也!

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            3 隨筆 :: 44 文章 :: 1 評論 :: 0 Trackbacks
          1:需要安裝數(shù)據(jù)庫的各種頭文件以及動(dòng)態(tài)庫如:
              
              MySQL-server-community-5.1.58-1.rhel4.i386.rpm
              MySQL-client-community-5.1.58-1.rhel4.i386.rpm
              MySQL-devel-community-5.1.58-1.rhel4.i386.rpm
              MySQL-shared-compat-5.1.58-1.rhel4.i386.rpm  (否則安裝mysql++會(huì)報(bào)錯(cuò),說鏈接客戶端失敗)

          2:安裝mysql++
             
               ./configure -> make -> make install

          3:編譯測試程序
          [zhichen@localhost src]$ vi test.cpp
              #include 
          "mysql++.h"
              
          using namespace mysqlpp;
              
          using namespace std;
              
          int main()
              {
                  
          //構(gòu)造一個(gè)Connection類的對象
                  Connection con(false);
                  
          const char* db = "mysql"*server = "127.0.0.1"*user = "pos"*pass = "pos";
                  
          if (con.connect(db, server, user, pass))
                  {
                      cout 
          << "success" << endl;
                      
          string sql = "select * from users";    
                      Query query 
          = con.query(sql);
                      
          if (StoreQueryResult rs = query.store())
                      {
                          StoreQueryResult::const_iterator it;
                          
          for (it = rs.begin(); it != rs.end(); ++it)
                          {
                              Row row 
          = *it;
                              cout 
          << "/t" << row[0<< "/t" << row[1<< endl;
                          }
                      }
                      
          else
                      {
                          cerr 
          << "Failed to get item list: " << endl;
                          
          return -1;
                      }
                  }
                  
          else
                  {
                      cout 
          << "Failed to connect DB" << con.error() << endl;
                      
          return -1;
                  }
                  
          return 0;
              }


          g++ -o test test.cpp -I/usr/include/mysql -I/usr/local/include/mysql++/ -L/usr/local/lib -lmysqlpp -lmysqlclient


          4:執(zhí)行./test
          如果報(bào)錯(cuò)說
          ./test: error while loading shared libraries: libmysqlpp.so.3: cannot open shared object file: No such file or directory

           man ldconfig
          vi /etc/ld.so.conf
          把mysq++動(dòng)態(tài)庫 /usr/local/lib的路徑加進(jìn)去

          5:再次執(zhí)行測試程序
          posted on 2011-11-03 20:32 goto 閱讀(593) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 荃湾区| 鄂温| 望城县| 永仁县| 余庆县| 南昌市| 新竹县| 吉水县| 津南区| 朝阳市| 视频| 云林县| 新竹县| 镇赉县| 北票市| 芜湖县| 多伦县| 禄劝| 弥勒县| 通海县| 广德县| 仪征市| 民和| 策勒县| 靖边县| 常熟市| 来宾市| 闵行区| 石棉县| 临汾市| 万州区| 馆陶县| 郎溪县| 岳池县| 新源县| 昌黎县| 黑山县| 乌拉特后旗| 沧源| 静乐县| 兴安盟|