Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C MySQL
I need to connect c and mysql
 
this is my program
 
#include stdio.h;
#include mysql.h;
#define host localhost;
#define username root;
#define password viswa;
#define database dbase;
MYSQL *conn;
 
int main()
{
 
    MYSQL_RES *res_set;
    MYSQL_ROW row;
 
    conn = mysql_init(NULL);
 
    if( conn == NULL )
    {
        printf("Failed to initate MySQL\n");
        return 1;
    }
 

    if( ! mysql_real_connect(conn,host,username,password,database,0,NULL,0) )
    {
        printf( "Error connecting to database: %s\n", mysql_error(conn));
        return 1;
    }
 
    unsigned int i;
 

    mysql_query(conn,"SELECT name, email, password FROM users");
 

    res_set = mysql_store_result(conn);
 

    unsigned int numrows = mysql_num_rows(res_set);
    unsigned int num_fields = mysql_num_fields(res_set);
 

 
    while ((row = mysql_fetch_row(res_set)) != NULL)
    {
 
        for(i = 0; i < num_fields; i++)
        {
             printf("%s\t", row[i] ? row[i] : "NULL");
        }
        printf("\n");
 
    }
 

    mysql_close(conn);
    return 0;
 
}
 

i got error "unabel to include mysql.h"
 
i am using windows 7, turbo c, mysql and i downloaded mysql-connector-c-noinstall-6.0.2-win32-vs2005, but dont know how to include it
 
thank you
Posted 25-Feb-12 2:10am
Edited 25-Feb-12 22:40pm
Comments
vishnupriyaraju at 25-Feb-12 7:15am
   
did you add reference of mysql to your application.
viswa317 at 25-Feb-12 8:24am
   
i don't understood
vishnupriyaraju at 25-Feb-12 13:40pm
   
If you are using vs 2005. Then you should add reference, so that only it will find mysql.h.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It doesn't know where to find mysql.h.
  Permalink  
Comments
viswa317 at 25-Feb-12 8:23am
   
how to solve this problem
John Simmons / outlaw programmer at 25-Feb-12 10:42am
   
Well, you add it to your project.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You should add the folder containing the mysql.h file to the include search path of your compiler.
  Permalink  
Comments
viswa317 at 26-Feb-12 0:04am
   
yes, that what i dont know how to do that....... please explan
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

The syntax of your include statements is incorrect, it's missing the delimiters, it should be:
#include <mysql.h>
// or
#include "mysql.h"
depending on whether mysql.h is in the system include directories or one of the project directories.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Follow the steps to add reference
project-> add reference-> "your reference"(mysql.h)
(This will workout if you use visual studio.)
  Permalink  
Comments
Richard MacCutchan at 26-Feb-12 3:52am
   
In C/C++?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

I used Linux, in windows i find it difficult.. now i got output perfectly
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 27 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100