Thread: How to connect C with MySql

  1. #1
    Registered User
    Join Date
    Aug 2020
    Posts
    10

    How to connect C with MySql

    Hi everyone,

    i am newbie in programming just started with C language to learn as my basic language and decided to create small app for accounting from the beginning with learning and developing same time.

    Sorry to ask but few questions not clear and i have mentioned below.

    I am using Dev C++ IDE, i dont know its good for C learning and developing but i like the Eclipse IDE however since i am in beginning i want to go with Dev C++ my version is 5.11 and i dont know how i can connect the Mysql database tables and queries to C functionality with Dev C++ IDE what connectors and plugins required, i want simple procedure and not so complex as i already wasted half of my day trying lot of things, however i have installed turbo C++ and Dev C++ and TDM GCC and mingW working fine i just want to add MySql to complete with compiling and debugging the codes.

    Any simple procedure will be appreciated.

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    846
    Although, I don't do MySQL development, I would start with this tutorial:
    MySQL C API programming tutorial

    There may be other, and possibly, better tutorials online.

    And the full reference to the MySQL documentation:
    MySQL :: MySQL 8.0 C API Developer Guide :: 6 C API Function Overview

    A Google search would provide much more information.

  3. #3
    Registered User
    Join Date
    Aug 2020
    Posts
    10
    Quote Originally Posted by rstanley View Post
    Although, I don't do MySQL development, I would start with this tutorial:
    MySQL C API programming tutorial

    There may be other, and possibly, better tutorials online.

    And the full reference to the MySQL documentation:
    MySQL :: MySQL 8.0 C API Developer Guide :: 6 C API Function Overview

    A Google search would provide much more information.

    Code:
    #include <stdio.h>#include <stdlib.h>
    
    
    
    
    int main()
    
    
    {
    
    
    	
    	int Value;
    	Value = 50;
    	
    	
    	int Multiplier
    	Printf("Enter the Multiplier :");
    	scanf("%d",&Multiplier);
    	
    	int Result
    	Result = Multiplier + Value;
    	Printf("\n The Result is : %d", Result);
    	getch();
    	
    	printf("This is my first language");
    	printf("\n Hello World");
    }
    What i am doing here wrong little confused about it?

  4. #4
    Registered User
    Join Date
    Aug 2020
    Posts
    10
    This is my first attempt with C language, I am confused what is wrong in below, value is defined and multiplier user have to input and the result should show the addition of both.

    What i am doing wrong here?

    Code:
    #include <stdio.h>#include <stdlib.h>
    
    
    
    
    int main()
    
    
    {
    
    
    	
    	int Value;
    	Value = 50;
    	
    	
    	int Multiplier
    	Printf("Enter the Multiplier :");
    	scanf("%d",&Multiplier);
    	
    	int Result
    	Result = Multiplier + Value;
    	Printf("\n The Result is : %d", Result);
    	getch();
    	
    	printf("This is my first language");
    	printf("\n Hello World");
    }

  5. #5
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    846
    Semicolons missing after declaring "int Multiplier" and "int Result".

    You can define and initialize a variable in one statement.
    Code:
    int Value = 50;
    "printf" not "Printf"

    getch() is not a linux function so I had to stub it out.

    Newlines are usually at the end of the printf() statements, not at the start.

    Turn on your warnings and turn up the warning level to the highest.

    Compare my version below to yours, line by line to see the corrections and changes I made.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void)
    {
        int Value;
        Value = 50;
    
        int Multiplier;
        printf("Enter the Multiplier :");
        scanf("%d",&Multiplier);
    
        int Result;
        Result = Multiplier + Value;
        printf("The Result is : %d\n", Result);
    //    getch();
    
        printf("This is my first language\n");
        printf("Hello World\n");
    
        return 0;
    }

  6. #6
    Registered User
    Join Date
    Aug 2020
    Posts
    10
    aaahhhh the problem was in front of me ; it kills me for two hours.

    i am using Dev C++ IDE how to set higher warning ?


    Thanks buddy love you.

  7. #7
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    846
    I don't use any IDE, but I found this:
    Dev-C++ Tutorial

    I use Emacs as my editor, and either compile on the command line, or "make" for anything larger than a one source file program. Most beginners spend too much time fighting with the IDE, while trying to learn the language.

    Dev C++ IDE is very outdated. If you do want or need an IDE, I would suggest switching to a more modern one that is regularly updated.

    See the Wikipedia article for a list of IDE's here:
    Comparison of integrated development environments - Wikipedia

  8. #8
    Registered User
    Join Date
    Aug 2020
    Posts
    10
    I have switched to VS editor looks good but need to learn in order to make coding effortless.

  9. #9
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    846
    Quote Originally Posted by mba_110 View Post
    I have switched to VS editor looks good but need to learn in order to make coding effortless.
    In order to learn the language properly, you need to either take a class from a qualifed instructor, or you need to study a good up to date book on the C Programming Language, cover to cover, and do all the exercises at the end of each chapter! Choose one of the three listed below:

    C Programming, A Modern Approach
    Author: K. N. King

    C Primer Plus, 6th Edition
    Stephen Prata

    C How to Program, 8/e
    Deitel & Deitel

    I would avoid any of the so-called on-line tutorials, or YouTube videos! They are painfully inadequate, and/or wrong!

    Good luck!

  10. #10
    Registered User
    Join Date
    Aug 2020
    Posts
    2
    rstanley, Although you're probably right regarding inadequate tutorials, this series is actually pretty good: C Programming – Features & The First C Program - YouTube I'd watched a couple of videos yesterday to falls asleep to while revising C knowledge (was trying to find whether it's possible to create scoped functions in C that could access auto variables), and he's not bad, short vids to the point and accurate too. Def a good channel for beginners - try pick a video from the playlist I doubt you'd be disappointed.

  11. #11
    Registered User
    Join Date
    May 2012
    Posts
    502
    Quote Originally Posted by zavr View Post
    rstanley, Although you're probably right regarding inadequate tutorials, this series is actually pretty good: C Programming – Features & The First C Program - YouTube I'd watched a couple of videos yesterday to falls asleep to while revising C knowledge (was trying to find whether it's possible to create scoped functions in C that could access auto variables), and he's not bad, short vids to the point and accurate too. Def a good channel for beginners - try pick a video from the playlist I doubt you'd be disappointed.
    A lot of people who know a lot about C but not much about teaching will tell you that tutorial materials are "bad" because they contain "errors", whilst in fact they contain simplifications to make the material easier to understand for a beginner. (Not to say that this is the case with anyone on this thread, just that it's a common tendency).

    However video isn't a very good medium of instruction. It has the advantage that you can show moving graphics. But you can't make them interactive. And whilst you can pause and replay sections, this is difficult. Text-based tutorials with illustrations are far better.
    Last edited by Malcolm McLean; 09-01-2020 at 04:46 AM.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,345
    Quote Originally Posted by Malcolm McLean
    But you can't make them interactive.
    I've seem some videos with interactive elements on Youtube, so it's not inconceivable that someone has managed to apply them effectively to tutorial videos.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    Registered User
    Join Date
    Aug 2020
    Posts
    10
    Sorry to disturb you again, i have made following code to calculate circle related algorithm.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {                               //Program to find area, circumference and diameter of circle based on Radius.
    
      float diameter;
      float circumference;
      float radius;
      float area;
      float pie;
      diameter = radius * 2;
      circumference = diameter * pie;
      radius = diameter / 2;
      area = radius * pie * radius;
      pie = circumference / diameter;
    
      // Enter the value of Radius for calculation of above.
      printf("Please enter the value of circle radius \n");
      scanf("%f", &radius);
    
      // Calculation of Pie
      printf("The Pie of Circle is %f\n", pie);
      //scanf("%f",&pie);
    
      // Calculation of Circle's Area.
      printf("The circle area is %f\n", area);
      //scanf("%f",&area);
    
      // Calculation of Circumference of Circle.
      printf("The Circumference of Circle is %f\n", circumference);
      //scanf("%f",&circumference);
    
      // Calculation of Diameter of Circle.
      printf("The Diameter of Circle is %f\n", diameter);
      //scanf("%f",&diameter);
    
    
      return 0;
    }
    i am looking the result of all pie,area,circumference,diameter after input of radius, but unable to get there.
    Last edited by Salem; 09-02-2020 at 09:35 PM. Reason: Removed crayola

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,710
    > diameter = radius * 2;
    Move all your calculations...

    > scanf("%f", &radius);
    AFTER you have read the input data for those calculations.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #15
    Registered User
    Join Date
    Aug 2020
    Posts
    10
    Not clear you are telling it in a very limited words, move what from what ? input data from what those calculations ?

    Not clear to understand anything, please write in details what actually required to do.

    here i want all values of pie,diameter,circumference and area based on radius i have provided, so once i input radius it should show four separate lines showing for category result.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C connect with mysql
    By Kinshara in forum C Programming
    Replies: 2
    Last Post: 01-16-2013, 02:44 AM
  2. how to connect borland c++ with mysql database
    By hdhd in forum C++ Programming
    Replies: 1
    Last Post: 02-11-2010, 03:34 PM
  3. how to connect mysql in mfc.
    By sgh in forum C++ Programming
    Replies: 1
    Last Post: 12-28-2008, 12:41 AM
  4. C++ connect to MySQL
    By thl in forum C++ Programming
    Replies: 1
    Last Post: 11-13-2006, 06:27 AM
  5. MySQL Connect from Outside Computer
    By juschillin in forum Windows Programming
    Replies: 0
    Last Post: 09-27-2002, 08:02 AM

Tags for this Thread