linux环境下写C++操作mysql(一)
16lz
2021-01-22
/***************** connect.cpp g++ connect.cpp -o connect -I /usr/include/mysql/ -L /usr/lib/mysql/ -lmysqlclient ****************/ #include<stdio.h> #include<string.h> #include<stdlib.h> #include"mysql.h" class CMysqlInterface { public: CMysqlInterface(); ~CMysqlInterface(); void mysqlLibInit(); void mysqlLibDestroy(); int Connect(); int Close(); private: MYSQL *m_mysqlPtr; }; int main() { printf("version 1.1\n"); int iRet = -1; CMysqlInterface MysqlObj; iRet = MysqlObj.Connect(); if(0 == iRet) { printf("mysql_real_connect success\n"); } else { printf("mysql_real_connect failed\n"); } return 0; } CMysqlInterface::CMysqlInterface() { printf("CMysqlInterface\n"); m_mysqlPtr = NULL; m_mysqlPtr = mysql_init(NULL); } CMysqlInterface::~CMysqlInterface() { Close(); } int CMysqlInterface::Close() { int iRet = 0; if(NULL != m_mysqlPtr) { mysql_close(m_mysqlPtr); m_mysqlPtr = NULL; } return iRet; } void CMysqlInterface::mysqlLibDestroy() { mysql_library_end(); } int CMysqlInterface::Connect() { printf("Connect\n"); int iRet = -1; m_mysqlPtr = mysql_real_connect(m_mysqlPtr,"localhost","root","csql","child",0,NULL,0); if(m_mysqlPtr) { iRet = 0; } return iRet; }
更多相关文章
- 字体图标的引入和通过媒体查询改变导航样式
- HTML样式和常用选择器
- 字体图标的引用和自定义样式/媒体查询的使用
- 数据库的CURD操作、PDO本质与原理的学习
- CSS之伪类选择器和简单盒子简单案例
- 伪类选择器与盒模型常用属性
- 伪类选择器-结构伪类、根据位置选择匹配
- 7.4——常用标签与应用场景之表格与单元格
- css伪类选择器和盒模型