RicardasSim

mysql_real_escape_string

Dec 27th, 2018
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <mysql.h>
  5.  
  6. MYSQL mysql;
  7.  
  8. int main (int argc, char **argv)
  9. {
  10.  
  11.     unsigned long result;
  12.     char prntStr[100]={0};
  13.    
  14.     /*
  15.      {'\x00','\x1a','\n','\'','\"','\r'}
  16.      HEX: {0x0,0x1A,0x0A,0x27,0x22,0x0D}  
  17.      DEC: {0,26,10,39,34,13}
  18.      */
  19.    
  20.     char testStr[]={'\x00','\x1a','\n','\'','\"','\r'};
  21.     int size = 6;
  22.    
  23.     if(!mysql_init(&mysql))
  24.     {
  25.         printf("Error initializing MySQL client\n");
  26.         return 1;
  27.     }
  28.  
  29.    
  30.     result = mysql_real_escape_string(&mysql,prntStr,testStr,size);
  31.    
  32.     if(result == (unsigned long)-1){
  33.         printf("an error occurs\n");
  34.     }
  35.     else{
  36.         printf("output: %s result: %ld\n",prntStr, result);
  37.     }
  38.    
  39.     mysql_close(&mysql);
  40.     mysql_library_end();
  41.  
  42.     return 0;
  43. }
  44.  
  45. /*
  46. output: \0\Z\n\'\"\r result: 12
  47. */
Advertisement
Add Comment
Please, Sign In to add comment