{
if(mysql_stmt_prepare(stmt,"INSERT test(col1,col2,col3,col4) values(?,?,?,?)", strlen("INSERT test(col1,col2,col3,col4) values(?,?,?,?)")))
{
fprintf(stderr,"mysql_stmt_prepare(), insert failed\r\n");
fprintf(stderr,"%s\r\n", mysql_stmt_error(stmt));returnfalse;
}//测试mysql_stmt_field_count()作用//printf("mysql_stmt_field_count return value[%d]\r\n",mysql_stmt_field_count(stmt));MYSQL_BIND bind[4];
unsignedlonglength[4];
my_bool is_null[4];
memset(bind,0,sizeof(bind));
memset(length,0,sizeof(length));
memset(is_null,0,sizeof(is_null));charvarchar_var[STRING_SIZE]="hello yg";charchar_var[STRING_SIZE]="hello dl";structst_stud st;
st.id=1;
strncpy(st.name,"shine.yang",16);
st.score=10.0f;
time_t cur_t=time(NULL);structtm cur_tm;
localtime_r(&cur_t,&cur_tm);
MYSQL_TIME ts;
ts.year=cur_tm.tm_year+1900, ts.month=cur_tm.tm_mon+1, ts.day=cur_tm.tm_mday,ts.hour=cur_tm.tm_hour, ts.minute=cur_tm.tm_min, ts.second=cur_tm.tm_sec;
bind[0].buffer_type=MYSQL_TYPE_STRING;
bind[0].buffer=varchar_var;
bind[0].buffer_length=STRING_SIZE;
length[0]=strlen(varchar_var);
bind[0].length=&length[0];
bind[0].is_null=&is_null[0];
bind[1].buffer_type=MYSQL_TYPE_STRING;
bind[1].buffer=char_var;
bind[1].buffer_length=STRING_SIZE;
length[1]=strlen(char_var);
bind[1].length=&length[1];
bind[1].is_null=&is_null[1];
bind[2].buffer_type=MYSQL_TYPE_BLOB;
bind[2].buffer=(char*)&st;
bind[2].buffer_length=sizeof(st);
length[2]=sizeof(st);
bind[2].length=&length[2];
bind[2].is_null=&is_null[2];
bind[3].buffer_type=MYSQL_TYPE_TIMESTAMP;
bind[3].buffer=(char*)&ts;
bind[3].buffer_length=sizeof(ts);
length[3]=sizeof(ts);
bind[3].length=&length[3];
bind[3].is_null=&is_null[3];
dword time1=get_time();for(inti=0; i
{if( mysql_stmt_bind_param(stmt,bind) )
{
fprintf(stderr,"mysql_stmt_bind_param failed,err = %s\r\n",mysql_stmt_error(stmt));returnfalse;
}if( mysql_stmt_execute(stmt) )
{
fprintf(stderr,"mysql_stmt_excute failed,err = %s\r\n",mysql_stmt_error(stmt));returnfalse;
}//printf("Total effect rows [%d]\r\n",(int)mysql_stmt_affected_rows(stmt));}
dword time2=get_time();
fprintf(stdout,"stmt insert %d items,during time[%d]\r\n",INSERT_ITEM_CNT,time2-time1);returntrue;
}