惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
量子位
博客园 - 司徒正美
V
V2EX
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
N
Netflix TechBlog - Medium
L
LangChain Blog
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
A
About on SuperTechFans
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - pipicfan

unity性能优化之Drawcall优化 谈谈我是如何面试技术人员的 Shader中颜色的加法和乘法的区别 unity性能优化-实际开发中需要注意的点 向字符数组中插入一个字符 cocos2dx 新手引导 c++面试题 c++实现委托 屁屁桌面管理 War3Tool dota改键v3.3版 魔兽全屏改键工具 很犀利的错误 关于vs2003环境支持win7 的 IP设置 自己的毕业设计windows管理软件 很容易犯的错误 敏感词过滤和谐社会1.0版 自己实现string类 用C++ 设计一个不能被继承的类 (转)字符编码笔记:ASCII,Unicode和UTF-8
宿舍计费系统105加强版
pipicfan · 2012-12-12 · via 博客园 - pipicfan
  1 // Conn.cpp: implementation of the CConn class.
  2 //
  3 //////////////////////////////////////////////////////////////////////
  4 
  5 #include "stdafx.h"
  6 #include "Sushe.h"
  7 #include "Conn.h"
  8 
  9 #ifdef _DEBUG
 10 #undef THIS_FILE
 11 static char THIS_FILE[]=__FILE__;
 12 #define new DEBUG_NEW
 13 #endif
 14 
 15 //////////////////////////////////////////////////////////////////////
 16 // Construction/Destruction
 17 //////////////////////////////////////////////////////////////////////
 18 
 19 //c++参数不确定
 20 //优化无止境的优化
 21 CMysqlCon::CMysqlCon(CString sqll)
 22 {
 23     sql=sqll;
 24     mysql_init(&mysql);
 25     
 26     if( !mysql_real_connect(&mysql,"localhost","root","123456","test",3306,NULL,0))
 27     {
 28         AfxMessageBox("连接数据库失败!");
 29     }
 30 
 31     mysql_set_character_set(&mysql, "gbk"); //设置语言栏支持中文
 32 
 33     if(mysql_real_query(&mysql,sql,sql.GetLength()) )
 34     {
 35         AfxMessageBox(sql);
 36         AfxMessageBox("err query!");
 37         assert(0);
 38     } 
 39 
 40     if(!(result=mysql_store_result(&mysql)))
 41     {
 42         AfxMessageBox("读取数据集失败");
 43         assert(0);
 44     }
 45     else
 46     {
 47         while(row =mysql_fetch_row(result)){;}
 48         count=mysql_num_rows(result);//行数
 49     }
 50 }
 51 
 52 CMysqlCon::~CMysqlCon()
 53 {
 54     
 55     mysql_free_result(result);
 56     mysql_close(&mysql);
 57 }
 58 
 59 
 60 
 61 bool CMysqlCon::HasData()
 62 {
 63     if(count>0)
 64     {
 65         return true;
 66     }
 67     else
 68     {
 69         return false;
 70     }
 71 }
 72 
 73 bool CMysqlCon::Querysql(CString sqll)
 74 {
 75         if( mysql_real_query(&mysql,sql,sql.GetLength()))
 76          {
 77              AfxMessageBox("err query!");
 78              assert(0);
 79              return 0;
 80          } 
 81 
 82         if(!(result=mysql_store_result(&mysql)))
 83         {
 84             AfxMessageBox("读取数据集失败");
 85             assert(0);
 86         }
 87         else
 88         {
 89             while(row =mysql_fetch_row(result)){;}
 90             count=mysql_num_rows(result);    //行数
 91         }
 92          return 1;
 93 }
 94 
 95 void CMysqlCon::DeleteById(CString id,CString biaoname)
 96 {
 97     CString sqll= "delete from" " "+biaoname+ " ""where id ="+id ;
 98     
 99     if( mysql_real_query(&mysql,sqll,sqll.GetLength()) )
100     {
101         AfxMessageBox("err query!");
102         assert(0);
103     } 
104     else
105         AfxMessageBox("删除成功");
106 }
107 
108 void CMysqlCon::UpdateById(CString Updateid,CString Updateusername,CString Updatemoney,CString Updatebeizhu)
109 {
110     
111     
112    CString sqll = "update sushe set username =" "'"+Updateusername+"'" "," "money=" "'"+Updatemoney+"'" "," "beizhu =" "'"+Updatebeizhu+"'" "where id =" "'"+Updateid+"'";
113 if( mysql_real_query(&mysql,sqll,sqll.GetLength()) )
114     {
115         AfxMessageBox("err update query!");
116         assert(0);
117     } 
118  else
119   {
120        AfxMessageBox("更新成功"); 
121   }
122 }
123 
124 void CMysqlCon::AddNewData(CString  insert_id,CString username,CString insert_money,CString insert_beizhu,CString timenow)
125 {
126 
127 
128     //timenow  ="2012-12-9 14:3:9";
129     CString  sqll = "insert into sushe(id,username,money,beizhu,time) values('" +insert_id+"'" "," "'" +username+"'" "," "'"+insert_money+"'" "," "'"+insert_beizhu+"'" "," "'"+timenow+"'" ")";
130 
131 
132     if( mysql_real_query(&mysql,sqll,sqll.GetLength()) )
133     {
134         AfxMessageBox(sqll);
135         assert(0);
136     } 
137 else
138 {
139   AfxMessageBox("插入成功");
140 
141 }
142 }
143 
144 
145 CString** CMysqlCon::GetAllData()
146 {
147     CString **arr;
148     count = mysql_num_rows(result);//行数
149     colNum = mysql_num_fields(result); //列数
150     arr = new CString* [count]; 
151     mysql_data_seek(result,0);
152     
153     for(int ii=0;ii<count;ii++)    
154     {    
155         if(row =mysql_fetch_row(result))
156         {
157             arr[ii]=new CString[colNum];
158 
159             for(int l=0;l<colNum;l++)    
160             {    
161                 if(row[l]==NULL   ||   !strlen(row[l])) 
162                 {
163                 }
164                     //AfxMessageBox("没有记录");   
165                 else    
166                 {
167                     arr[ii][l]=row[l];
168                 }  
169             } 
170         }
171         else
172         {
173             AfxMessageBox("nothing!");
174         }
175     }
176     
177     return arr;
178 }
179 
180 CString * CMysqlCon::GetColumn()
181 {
182     CString* arr;             //指针转换为堆空间 
183     MYSQL_FIELD *field;
184 
185     arr=new CString[colNum];
186     int i=0;
187 
188     while((field = mysql_fetch_field(result)))
189     {
190      arr[i++]=field->name;
191     }
192     return arr;
193 }
194 
195 CMysqlCon::CMysqlCon()
196 {    
197     mysql_init(&mysql);
198     
199     if( !mysql_real_connect(&mysql,"localhost","root","koolma2010","tcims",3306,NULL,0))
200     {
201         AfxMessageBox("连接数据库失败!");
202     }
203     mysql_set_character_set(&mysql, "gbk");
204 }