av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

MySQL數(shù)據表中插入數(shù)據并查詢輸出的實現(xiàn)

MySQL數(shù)據表中插入數(shù)據是我們很常見的操作,下面就為您詳細介紹MySQL數(shù)據表中插入數(shù)據并查詢輸出的實現(xiàn)方法步驟,如果您對MySQL數(shù)據表方面感興趣的話,不妨一看。

創(chuàng)新互聯(lián)是專業(yè)的饒平網站建設公司,饒平接單;提供網站制作、網站設計,網頁設計,網站設計,建網站,PHP網站建設等專業(yè)做網站服務;采用PHP框架,可快速的進行饒平網站開發(fā)網頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網站,專業(yè)的做網站團隊,希望更多企業(yè)前來合作!

 
 
 
  1. CREATE TABLE demotable (   
  2. id int(11) NOT NULL auto_increment,   
  3. demodata varchar(255) default NULL,   
  4. PRIMARY KEY (id)   
  5. ) TYPE=MyISAM;  
  6.  
  7. ----------往數(shù)據表中插入數(shù)據并查詢輸出----------  
  8. #include  /* Headers for MySQL usage */   
  9. #include    
  10. #include    
  11. #include    
  12.  
  13. int main(int argc, char **argv){  
  14. MYSQL demo_db;  
  15. mysql_init(&demo_db);  
  16.  
  17. int insert_id;   
  18. char *encdata, *query;   
  19. int datasize;   
  20. MYSQL_RES *res; /* To be used to fetch information into */   
  21. MYSQL_ROW row;   
  22.  
  23. if(argc<2){   
  24.     printf("Please supply a string for insertion into the database\n");   
  25.     exit(0);   
  26. }   
  27.  
  28. if(!mysql_real_connect(&demo_db, "localhost", "root", "mysql", "demodb", 0, NULL, 0)){   
  29.     printf(mysql_error(&demo_db));   
  30.     exit(1);   
  31. }   
  32.  
  33. // if(mysql_select_db(&demo_db, "demodb")){ /* Select the database we want to use */   
  34. //    printf(mysql_error(&demo_db));   
  35. //    exit(1);   
  36. // }   
  37.  
  38. encdata=malloc(2*strlen(argv[1])+1);   
  39.  
  40. datasize=mysql_real_escape_string(&demo_db, encdata, argv[1], strlen(argv[1]));   
  41. //printf("%s\n",encdata);  
  42.  
  43. query=malloc(datasize+255);   
  44. sprintf(query, "INSERT INTO demotable(demodata) VALUES('%s')", encdata); /* Build query */  
  45. //printf("%s\n",query);  
  46.  
  47. if(mysql_real_query(&demo_db, query, strlen(query))){ /* Make query */   
  48.      printf(mysql_error(&demo_db));   
  49.      exit(1);   
  50. }   
  51. free(query);   
  52.  
  53. insert_id=mysql_insert_id(&demo_db); /* Find what id that data was given */   
  54.  
  55. query=malloc(255);   
  56. sprintf(query, "SELECT demodata FROM demotable WHERE id=%d", insert_id);   
  57. if(mysql_real_query(&demo_db, query, strlen(query))){ /* Make query */   
  58.      printf(mysql_error(&demo_db));   
  59.      exit(1);   
  60. }  
  61. free(query);   
  62.  
  63. res=mysql_store_result(&demo_db); /* Download result from server */   
  64. row=mysql_fetch_row(res); /* Get a row from the results */   
  65. printf("You inserted \"%s\".\n", row[0]);   
  66. mysql_free_result(res); /* Release memory used to store results. */   
  67. mysql_close(&demo_db);   
  68.  
  69. return 0;   
  70. }   
  71.  
  72.  

分享標題:MySQL數(shù)據表中插入數(shù)據并查詢輸出的實現(xiàn)
本文路徑:http://uogjgqi.cn/article/cocejee.html
掃二維碼與項目經理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網交流