gcarpanetti 0 Newbie Poster

Hello everyone.
First of all apologies for my english. It is not my native languate and also if i break any good practice. It is my first Post.
I'm triying to learn CGI programming in C. Just for learn purposes and i have been triying litle step by step tests.
First i did the hello world and it worked, then i made the CGI read a data file in a folder outside the cgi-bin but inside the /var/www.
I'm working on an Amazon Ec2 instante with Amazon Linux (i think is some kind of CentOS).
I think my Apache is weel configured.
The thing is that now i'm triying to connect to MySQL, i used a code i found on the Internet and manage to compiled it but i get an internal server error (500) with no details.
i'd like to know, if someone can help me, what is wrong. I guess there are a lot of security and permissions to acomplish this but i don't know them (yet).
Thanks.

This is the code i used(from https://blog.openalfa.com/como-conectarse-a-una-base-de-datos-mysql-desde-un-programa-c-en-linux):

/* Sencillo programa C que establece una conexión a un servidor de base de datos MySQL */
#include <stdlib.h>
#include <stdio.h>
#include <mysql.h>
main() {
 MYSQL *conn;
 MYSQL_RES *res;
 MYSQL_ROW row;
 char *server = "localhost";
 char *user = "root";
 char *password = "PASSWORD"; /* Poner la contraseña */
 char *database = "mysql";
 conn = mysql_init(NULL);
 /* Conectarse a la base de datos */
 if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
     fprintf(stderr, "%s\n", mysql_error(conn));
     exit(1);
 }
 /* enviar la consulta SQL */
 if (mysql_query(conn, "show tables")) {
     fprintf(stderr, "%s\n", mysql_error(conn));
     exit(1);
 }
 res = mysql_use_result(conn);
 /* imprimir los nombres de las tablas */
 printf("Tablas en la base de datos 'mysql':\n");
 while ((row = mysql_fetch_row(res)) != NULL) printf("%s \n", row[0]);
 /* liberar los recursos y cerrar la conexion */
 mysql_free_result(res);
 mysql_close(conn);
}

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.