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

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            3 隨筆 :: 44 文章 :: 1 評論 :: 0 Trackbacks
          1:需要安裝數據庫的各種頭文件以及動態庫如:
              
              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++會報錯,說鏈接客戶端失敗)

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

          3:編譯測試程序
          [zhichen@localhost src]$ vi test.cpp
              #include 
          "mysql++.h"
              
          using namespace mysqlpp;
              
          using namespace std;
              
          int main()
              {
                  
          //構造一個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:執行./test
          如果報錯說
          ./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++動態庫 /usr/local/lib的路徑加進去

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

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


          網站導航:
           
          主站蜘蛛池模板: 荔浦县| 读书| 增城市| 乐清市| 翁牛特旗| 嘉义县| 博白县| 丘北县| 房产| 紫云| 松原市| 涞源县| 锡林郭勒盟| 司法| 休宁县| 杭锦旗| 鄂托克前旗| 龙口市| 东海县| 东乡| 名山县| 内黄县| 隆尧县| 宁陕县| 松滋市| 阿合奇县| 景洪市| 根河市| 永福县| 沿河| 牙克石市| 石首市| 阿合奇县| 封开县| 合水县| 岢岚县| 厦门市| 隆安县| 全州县| 会同县| 沾益县|