Guest User

Untitled

a guest
Aug 5th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <windows.h>
  6. #include <winsock.h>
  7. //#include <my_global.h>
  8. //#include <my_sys.h>
  9. #include <mysql/mysql.h>
  10. #include <string>
  11.  
  12. using namespace std;
  13.  
  14.  
  15.  
  16.  
  17.  
  18. //typedef unsigned int uint;
  19.  
  20. void getrow();
  21.  
  22. int main()
  23. {
  24.  
  25. string asd("dupa");
  26. MYSQL *conn;
  27. MYSQL_RES *res, *result;
  28. MYSQL_ROW row;
  29. int num_fields;
  30. int i;
  31.  
  32.  
  33.  
  34. char *server = "127.0.0.1";
  35. char *user = "root";
  36. char *password = "";
  37. char *database = "projekt"; // nazwa bazy
  38. conn = mysql_init(NULL);
  39. /* Connect to database */
  40. if (!mysql_real_connect(conn, server,
  41. user, password, database, 0, NULL, 0)) {
  42. fprintf(stderr, "%sn", mysql_error(conn));
  43. exit(1);
  44. }
  45. /* send SQL query */
  46. if (mysql_query(conn, "show tables")) {
  47. fprintf(stderr, "%sn", mysql_error(conn));
  48. exit(1);
  49. }
  50. res = mysql_use_result(conn);
  51. /* output table name */
  52. printf("MySQL Tables in mysql database:\n");
  53. while ((row = mysql_fetch_row(res)) != NULL)
  54. printf("%s \n", row[0]);
  55.  
  56.  
  57.  
  58. mysql_query(conn, "SELECT * FROM m_ksm_arch");
  59. result = mysql_store_result(conn); // wynik zapytania
  60. num_fields = mysql_num_fields(result); // pobierz ilosc pol
  61. row = mysql_fetch_row(result);
  62. cout << *row << endl;
  63.  
  64. // wypisanie jednej linii
  65. for ( int j = 0; j < 500; j++) {
  66. row = mysql_fetch_row(result);
  67. for(i = 0; i < num_fields; i++)
  68. {
  69. printf("%s ", row[i] ? row[i] : "NULL");
  70. }
  71. printf("\n ");
  72.  
  73. }
  74.  
  75.  
  76.  
  77. /* close connection */
  78. mysql_free_result(res);
  79. mysql_close(conn);
  80. system("PAUSE");
  81. return 0;
  82. }
Add Comment
Please, Sign In to add comment