Guest User

Untitled

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