Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. /* Simple C program that connects to MySQL Database server*/
  2. #include <mysql.h>
  3. #include <stdio.h>
  4.  
  5. main() {
  6. MYSQL *conn;
  7. MYSQL_RES *res;
  8. MYSQL_ROW row;
  9.  
  10. char *server = "localhost";
  11. char *user = "nobody";
  12. char *password = "noboody"; /* set me first */
  13. char *database = "mysql";
  14.  
  15. conn = mysql_init(NULL);
  16.  
  17. /* Connect to database */
  18. if (!mysql_real_connect(conn, server,
  19. user, password, database, 0, NULL, 0)) {
  20. fprintf(stderr, "%s\n", mysql_error(conn));
  21. exit(1);
  22. }
  23.  
  24. /* send SQL query */
  25. if (mysql_query(conn, "show tables")) {
  26. fprintf(stderr, "%s\n", mysql_error(conn));
  27. exit(1);
  28. }
  29.  
  30. res = mysql_use_result(conn);
  31.  
  32. /* output table name */
  33. printf("MySQL Tables in mysql database:\n");
  34. while ((row = mysql_fetch_row(res)) != NULL)
  35. printf("%s \n", row[0]);
  36.  
  37. /* close connection */
  38. mysql_free_result(res);
  39. mysql_close(conn);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement