Advertisement
Guest User

little-e

a guest
May 29th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <pwd.h>
  7. #include <unistd.h>
  8. #include <fcntl.h>
  9. #include <grp.h>
  10.  
  11. /* gcc hello.c -o hello -I/usr/include/mysql/ -std=gnu99 -lmysqlclient */
  12. /* Simple C program that connects to MySQL Database server*/
  13. #include <mysql.h>
  14. #include <stdio.h>
  15. int main() {
  16. MYSQL *conn;
  17. MYSQL_RES *res;
  18. MYSQL_ROW row;
  19. char *server = "localhost";
  20. char *user = "root";
  21. char *password = "bleh";
  22. char *database = "oxwall";
  23. conn = mysql_init(NULL);
  24.  
  25. FILE *pfd = popen( "wc -l /usr/local/sbin/memcached-1.4.22/lines | gawk '{print $1}'", "r" );
  26. const size_t BUFSZ = 1024;
  27. char *buf = malloc( BUFSZ );
  28. size_t bufPos = 0;
  29. while (1)
  30. {
  31. bufPos += fread( buf+bufPos, 1, BUFSZ, pfd );
  32. if ( !feof(pfd) )
  33. {
  34. buf = realloc( buf, bufPos + BUFSZ );
  35. }
  36. else
  37. {
  38. break;
  39. }
  40. }
  41. pclose( pfd );
  42. free( buf );
  43.  
  44. int exsdeaewzs;
  45. exsdeaewzs = atoi(buf);
  46.  
  47. /* Connect to database */
  48. if (!mysql_real_connect(conn, server,
  49. user, password, database, 0, NULL, 0)) {
  50. fprintf(stderr, "%s\n", mysql_error(conn));
  51. exit(1);
  52. }
  53.  
  54. char* wzarsa = "SELECT zcdafxe FROM xtwarxzws ORDER BY id DESC LIMIT 1";
  55.  
  56. mysql_query(conn, wzarsa);
  57.  
  58. res = mysql_use_result(conn);
  59.  
  60. while ((row = mysql_fetch_row(res)) != NULL)
  61. printf("%s \n", row[0]);
  62.  
  63. char* sql = malloc(100);
  64. char append[256];
  65.  
  66. /* sql = "INSERT INTO xtwarxzws VALUES('zcdafxe', 671)"; */
  67.  
  68. strcpy(sql, "INSERT INTO xtwarxzws VALUES('zcdafxe', ");
  69. sprintf(append,"%d",exsdeaewzs);
  70. strcat(sql, append);
  71. strcat(sql, "\x29");
  72.  
  73. if (mysql_query(conn, sql)) {
  74. fprintf(stderr, "%s\n", mysql_error(conn));
  75. exit(1);
  76. }
  77.  
  78. mysql_free_result(res);
  79. mysql_close(conn);
  80.  
  81.  
  82.  
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement