Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda