mysqltest.cpp
来自「mysql的接口实现 执行sql语句 example: select * f」· C++ 代码 · 共 64 行
CPP
64 行
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <mysql/mysql.h>#include "Mysqlport.h"int main(){ MYSQL_ROW rec; MYSQL_RES *res; res = NULL; int flag; printf("1111\n"); CSqlPort thsql; printf("2222\n"); flag = thsql.OpenSQL(); if(flag == 0) { res = thsql.SqlQuery("SELECT * FROM mytable;"); printf("3333\n"); if(res != NULL) { printf("***********************************************\n"); while(rec = mysql_fetch_row(res)) { printf("%s - %s \n",rec[0],rec[1]); } printf("***********************************************\n"); printf("4444\n"); mysql_free_result(res); printf("5555\n"); thsql.Begin(); printf("6666\n"); if(thsql.SqlCmd("INSERT INTO mytable (cc) VALUES ('44');") == 0) { printf("7777\n"); thsql.RollBack(); } else { printf("8888\n"); thsql.RollBack(); } } mysql_free_result(res); printf("***************\n"); thsql.Transcation("INSERT INTO mytable (cc) VALUES ('55');"); printf("9999\n"); thsql.CloseSQL(); } else { printf("*********ERROR*************\n"); thsql.CloseSQL(); } printf("end\n"); return EXIT_SUCCESS;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?