Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

273
Vistas
How to connect and code a C Program with a MySQL database in Windows?

I have recently learned MySQL and I want to implement the knowledge on how to build a C Program using MySQL database on windows. Can anyone provide me with a detailed description on which files to download and whether I need XAMPP running or not?

I have tried to read the documentation here : https://dev.mysql.com/doc/refman/8.0/en/c-api-implementations.html . However , I couldn't figure out for my life how to do it on Windows.(Seems pretty easy for Linux, unfortunately I do not have a Linux machine)

It would be great if someone would provide me with a detailed and step by step explanation. Thanks in advance.

I know how the code would look like.

#include <stdio.h>
#include <stdlib.h>
#include <my_global.h>
#include <mysql.h>

typedef struct
{
    char host[20];
    char user[25];
    char pass[50];
}DB_CONN_PARAMS;

MYSQL * connect_db(DB_CONN_PARAMS *params)
{
    MYSQL *connection = mysql_init(NULL);//init connection
    if (connection == NULL)
    {//check init worked
        fprintf(stderr, "%s\n", mysql_error(connection));
        exit(EXIT_FAILURE):
    }
    //connect:
    if (mysql_real_connect(
            connection,
            params->host,
            params->user,
            params->pass,
            NULL,0,NULL,0)
        ==NULL)
    {//connection failed?
        fprintf(stderr, "%s\n", mysql_error(connection));
        mysql_close(connection);
        exit(EXIT_FAILURE):
    }
    return connection;
}

int main()
{
    MYSQL *db;
    DB_CONN_PARAMS *params = calloc(1,sizeof(DB_CONN_PARAMS));
    //just an alternative way of passing connection params, find a struct easier
    params->host = "127.0.0.1";
    params->user = "root";
    params->pass = "mySuperSecretPass";
    MYSQL * connect_db(DB_CONN_PARAMS *params);
    db = connect_db(params);
    //we don't need the struct anymore
    free(params);
    params = NULL;
    //do stuff
    mysql_close(db);//close connection, of course!
    return EXIT_SUCCESS;
}

I just need help with the setup.

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda