| | |
| | | cout << "Failed to initialize MySQL." << endl; |
| | | return; |
| | | } |
| | | // 设置å符é |
| | | if (m_mysql) mysql_set_character_set(m_mysql, "gbk"); |
| | | // 使ç¨åæ»çåæ°è¿æ¥æ°æ®åº |
| | | m_mysql = mysql_real_connect(m_mysql, "127.0.0.1", "root", "123456", "mayi_kunlun", 3306, nullptr, 0); |
| | | if (!m_mysql) { |
| | |
| | | m_mysql = nullptr; |
| | | } |
| | | // åå§å row_ å res_ |
| | | if (m_mysql) mysql_set_character_set(m_mysql, "gbk"); |
| | | m_row = nullptr; |
| | | m_res = nullptr; |
| | | } |
| | | bool MysqlConn::isConnected() { |
| | | return m_mysql != nullptr; |
| | | } |
| | | // è¿æ¥æ°æ®åº |
| | | //bool MysqlConn::connect() { |
| | | // string ip = "127.0.0.1"; |
| | | // string userName = "root"; |
| | | // string passwd = "123456"; |
| | | // string db = "mayi_kunlun"; |
| | | // int port = 3306; |
| | | // m_mysql = mysql_real_connect(mysql_, ip.c_str(), userName.c_str(), passwd.c_str(), db.c_str(), port, nullptr, 0); |
| | | // if (!m_mysql) { |
| | | // return false; |
| | | // } |
| | | // return true; |
| | | //} |
| | | |
| | | // éæ¾èµæº |
| | | MysqlConn::~MysqlConn() { |
| | |
| | | } |
| | | int paramCount = mysql_stmt_param_count(stmt); |
| | | if (paramCount > 0) { |
| | | // 妿æåæ°ï¼éè¦è¿è¡åæ°ç»å®çæä½ï¼è¿éæä¸å®ç° |
| | | mysql_stmt_close(stmt); |
| | | return false; |
| | | } |
| | |
| | | //int col_cnt = m_mysql->field_count; |
| | | int col_cnt = mysql_field_count(m_mysql); |
| | | cout << col_cnt << endl; |
| | | MYSQL_ROW m_row; |
| | | while (m_row = mysql_fetch_row(m_res)) { |
| | | vector<string> tmp; |
| | | for (int i = 0; i < col_cnt; i++) { |
| | |
| | | // æ¥è¯¢æ°æ®åº |
| | | bool MysqlConn::query(string sql) { |
| | | freeRes(); |
| | | // åæ°åæ¥è¯¢ä¼ååçå®å
¨æ£æ¥ |
| | | //åæ°åæ¥è¯¢ä¼ååçå®å
¨æ£æ¥ |
| | | MYSQL_STMT* stmt = mysql_stmt_init(m_mysql); |
| | | if (!stmt) { |
| | | return false; |