引自 http://group.gimoo.net/review/57321 文章的评论
mysql++这个东西配置起来是比较麻烦,也没什么说明,要设置包含一堆东西,新手应该会比较头疼的。
其实很简单,下载mysql++的源码,然后打开解决方案,vc2008或者vc2005里面,编译之后就能看见几个dll和lib文件,lib是编译时需要的,而dll是你运行时需要的。
我自己做了一个头文件,以便以后工程里用的时候比较简单点。
发出来你看着用吧。
C/C++ code //-----------------------mysql++ header-------------------------------------------------- #ifndef MYSQL_NEED_HEADER #define MYSQL_NEED_HEADER //#include <winsock.h> #include <windowsx.h> #include "./mysql++/include/mysql++.h" #ifdef WIN32 #ifdef NDEBUG #pragma comment (lib,"./mysql++/lib/release/libmysql.lib") #pragma comment (lib,"./mysql++/lib/release/mysqlpp.lib") #pragma comment (lib,"./mysql++/lib/release/mysqlpp_excommon.lib") #else #pragma comment (lib,"./mysql++/lib/debug/libmysql.lib") #pragma comment (lib,"./mysql++/lib/debug/mysqlpp.lib") #pragma comment (lib,"./mysql++/lib/debug/mysqlpp_excommon.lib") #endif #endif #endif //手动设置附加包含目录"./mysql++/mysql" //设置生成后事件 copy ./mysql++/lib/release/*.dll ./release
winsock.h和windows.h都是mysql编译需要的文件
当然不要忘了mysqlpp同样需要mysql原本的库,都设置好以后就ok了。祝你成功~!
引自 http://www.diybl.com/course/7_databases/sql/sqlServer/2008617/125676.html
1.首先安装MySQL5.0;
2.在http://tangentsoft.net/mysql++/ 下载mysql++-3.0.3.tar.gz (3.1 MB, 2008.05.11) ;
3.下载后解压缩至F盘(我的是解压缩到F),后打开F:/mysql++-3.0.3/vc2005/mysql++.sln,后用vc2005打开此文件;
4.按F7或生成->生成解决方案,这个时间有点长,请耐心等待。后到该文件的同目录Debug下找到mysqlpp_d.dll文件;
5.在vc2005下工具->选项->项目解决方案->VC++目录->包含文件和库文件,包含该dll文件(F:/mysql++-3.0.3/lib)和F:/mysql++-3.0.3/vc2005/Debug。
6.现在新建一个项目,设置该项目的属性->配置属性->链接器->输入->附加依赖项中加入mysqlpp_d.lib mysqlpp_excommon.lib,两者之间是加的空格而不是逗号。
7.加入以下的代码:
#include <mysql++.h> #include <iostream> #include <iomanip> using namespace std; using namespace mysqlpp; int main(int argc, char *argv[]) { Connection conn("mydb","localhost","root","sanweizju"); Query query=conn.query(); query<<"select * from mytable"; StoreQueryResult res=query.store(); Row row; cout.setf(ios::left); StoreQueryResult::iterator i; for (i=res.begin();i!=res.end();i++) { row=*i; cout<<setw(5)<<row[0]<<setw(10)<<row[1]<<setw(10)<<row[2]<<endl; } //query<<"insert into mytable values(null,'MYSQL++','MYSQL++','MYSQL++','')"; //query.execute( ); //query<<"delete from mytable where id>10&&id<20"; //query.execute(); //cout<<query.affected_rows()<<endl; getchar(); } 成功编译运行!