日期:2014-05-16 浏览次数:20832 次
#include<stdio.h> #include<winsock.h> #include<mysql.h> #include<windows.h> #pragma comment(lib,"libmysql.lib") int main(int argc,char* argv[]) { MessageBox(NULL,"init...","ok",MB_OK); unsigned short Port= 3307; char *IPAddress= "127.0.0.1"; char *UserName= "root"; char *Password= "nomima"; char *DBName= "test"; printf("Start..."); MYSQL *ssock; MYSQL*conn; ssock= (MYSQL*)malloc(sizeof(MYSQL)); MessageBox(NULL,"init...","ok",MB_OK); mysql_init(ssock);//怀疑这里有问题 if(ssock==NULL) { printf("EROR: MySQL ssock init error."); return FALSE; } ssock= mysql_real_connect(ssock, IPAddress, UserName, Password, NULL, Port, NULL,0); if(!ssock) { printf("conn fail..."); unsigned int mtint= mysql_errno(ssock); return FALSE; } if(mysql_select_db(ssock, DBName)!= 0) { printf("select db error."); return FALSE; } printf("version=%d", mysql_get_server_version(ssock)); mysql_close(ssock); printf("End..."); return TRUE; }