title: Connecting to MySQL with XAMPP client in C
body: <pre><code>#include &lt;mysql.h&gt;
  #include &lt;stdio.h&gt;
  
  int main() {
    MYSQL *conn;
    MYSQL_RES *res;
    MYSQL_ROW row;
  
    char *server = "localhost";
    char *user = "root";
    char *password = ""; // set me first
    char *database = "VirtualSoc";
    conn = mysql_init(NULL);
  
    /* Connect to database */
    if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
      fprintf(stderr, "%s\n", mysql_error(conn));
      exit(1);
    }
  
    /* send SQL query */
    if (mysql_query(conn, "show tables")) {
      fprintf(stderr, "%s\n", mysql_error(conn));
      exit(1);
    }
    res = mysql_use_result(conn);
  
    /* output table name */
    printf("MySQL Tables in mysql database:\n");
    while ((row = mysql_fetch_row(res)) != NULL)
      printf("%s \n", row[0]);
  
    /* close connection */
    mysql_free_result(res);
    mysql_close(conn);
  }
  </code></pre>
  
  <p>This is the entire code. I'm trying to connect to a database under Linux. </p>
  
  <p>How do I compile this?<br>
  Why am I getting an error saying that <code>mysql.h doesn't exist</code>?<br>
  Do I need to use something like libmysqlclient-dev or libmariadbclient-dev use <code>mysql.h</code>? </p>
  
  <p>I don't want to use these, I just want to connect to my XAMPP server as localhost on my machine. How can I do that? And another question: why should I compile my code like this?</p>
  
  <blockquote>
    <p>$gcc -o output-file $(mysql_config --cflags) mysql-c-api.c $(mysql_config --libs)</p>
  </blockquote>