代码:) b1 f! O) k$ }, ]6 Y& J1 z
#include " l- _9 C$ l9 q: k+ L& |1 b$ R1 e( b* Z
#include
, `7 g$ W$ o# N #include "/usr/local/include/mysql/mysql.h" //安装的mysql的头文件所在的位置+ ^1 f5 Y2 L+ j) n7 y
using namespace std;
4 u: V' g: s" v) g/ g5 @+ ~1 }7 ` string host="数据库地址";
1 W( |& u5 R! t- Y5 R( ?5 t2 X string user="用户名";
) k3 M' q. d! s% T string pwd="密码";
+ [( X0 G# P- G1 M! l6 L string dbname="数据库";
8 e: S% B$ l& }3 f string sql="查询语句";
1 d# s4 N. P; r, O, ^! q7 b unsigned int port=3309;#端口号
) @. c$ s) H1 y int status;8 I" _* Q$ S' n1 J
int main(){
# H+ o2 t& ?% Q- c- c: \8 V& C MYSQL *mysql;; F% d6 s2 z6 b: ^& W% U
mysql=mysql_init(0);. t5 J: s, v) S
MYSQL_RES *result;
; l( {( k n$ I- l2 R MYSQL_ROW row;
+ O2 `0 j: X3 {0 F" G if(mysql_real_connect(mysql,host.c_str(),user.c_str(),pwd.c_str(),dbname.c_str(),port,NULL,CLIENT_FOUND_ROWS)==NULL){
3 l2 i( V4 L$ r4 }5 n7 Y cout |