欢迎选择我的课程,让我们一起见证您的进步~~
char sql[1024]= "insert into list values(?)"; char value[]= "192.168.1.1"; MYSQL_STMT* stmt ; MYSQL_BIND bind[1]; unsigned long val_len ; // mysql is MYSQL* mysql mysql_init(mysql); stmt = mysql_stmt_init(mysql); if(!stmt) { //error } if(mysql_stmt_prepare(stmt,sql, strlen(sql)) ) { // error } // bind value memset(bind,0,sizeof(bind)); bind[0].buffer_type=MYSQL_TYPE_STRING ; bind[0].buffer = (char*)value ; bind[0].length = &val_len ; bind[0].buffer_length = strlen(value); bind[0].is_null = 0 ; bind[0].is_error = 0 ; val_len = strlen(value); mysql_stmt_bind_param(stmt,bind); // execute if(mysql_stmt_execute(stmt) ) { //error } // close mysql_stmt mysql_stmt_close(stmt) ;
char sql[1024]; sprintf(sql,"INSERT INTO %s xxx VALUES('%s'),'list','localhost');//这里可以把list和localhost换成你的变量
char sql[1024];
sprintf(sql,"INSERT INTO %s xxx VALUES('%s'),'list','localhost');//这里可以把list和localhost换成你的变量