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

            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++會報錯,說鏈接客戶端失?。?br />
          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)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 大城县| 定南县| 凌海市| 永川市| 汕尾市| 武宁县| 林芝县| 敦化市| 武宣县| 蚌埠市| 长沙县| 山阳县| 满城县| 两当县| 宝清县| 七台河市| 阜南县| 湖州市| 融水| 云林县| 丰都县| 会东县| 沙洋县| 土默特右旗| 井研县| 乐亭县| 忻城县| 博乐市| 全州县| 阜平县| 长乐市| 贵港市| 积石山| 德兴市| 阳东县| 茂名市| 临夏县| 三穗县| 呼图壁县| 伊春市| 建平县|