7

I am working on a problem where I need to store and retrive the data from the database . I am using C for that on windows system . I am familiar with MYSQL database . I just need to know whether its possible for me to access database using C if yes which IDE I can use and how can I connect it to MYSQL .

3 Answers 3

12

Yes, you can connect your C code to MySQL using a connector (driver) available on MySql home page: http://www.mysql.com/products/connector/

There is a nice tutorial on writing C programs accessing MySQL: MySQL C API programming tutorial

You can use any IDE you want for writing your code, for example Visual Studio. Here you can download a free version: http://www.microsoft.com/visualstudio/11/en-us/products/express

Sign up to request clarification or add additional context in comments.

Comments

7

Yes, of course you can. You just need to download MySQL libraries. Here simple example of how to use it:

#include <stdio.h> 
#include "mysql/mysql.h" 

int main() { 
    MYSQL mysql; 

    if(mysql_init(&mysql)==NULL) { 
        printf("\nInitialization error\n"); 
        return 0; 
    } 

    mysql_real_connect(&mysql,"localhost","user","pass","dbname",0,NULL,0); 

    printf("Client version: %s",mysql_get_client_info()); 
    printf("\nServer version: %s",mysql_get_server_info(&mysql)); 
    mysql_close(&mysql); 
    return 1; 
}

You can use anyone IDE you want to. All you need is to set paths for include, lib and bin folders in MySQL.

2 Comments

I am trying to use codeblocks for it . Can you say me the procedure ?
The easiest way is to copy these three folders to folder where you have your compiler, which is mingw as i suppose
1

I write a library in C++ for database access. With this library you can connect e retrieve data from postgresql, mysql and mysql.

You can get the code here: https://github.com/vitorluis/VSQL

And you can try out this library and share with other people.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.