Thread: C Mysql Api

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    4

    C Mysql Api

    hi all..
    can anybody point me how to insert into database tables,using Structures in C.
    i'm using MYSQL.
    code:
    ---------------------------------
    typedef struct{
    int id;
    int frequency;
    int mod;
    }my_struct;

    my_struct *abc={
    {1,10,22},
    {(0,0,0)}
    };

    --------------------------------------
    i want to insert this sample entries into table 'channel'...
    please help me with the proper query for this..

    any response is highly appretiated.
    thanks in advance.
    fazz.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    So . . . you want your C program to automate typing commands?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    4
    yeah,
    actually my insert fuction has to take struct-pointer as argument,and
    insert into corresponding columns in the 'channel' table,like this:
    --------------------
    my_error Insert_channel (my_struct* list, int items) // items is the number of list items.
    ------------------------
    eg.
    my_struct abc={
    {1,10,22},
    {0,0,0}
    };
    /*Return :
    my_error
    Input Arguments:
    List (Null terminated structure)
    Items (no of items in the structure)
    -------------------------
    plz reply ...
    thanks.
    fazz

  4. #4
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    And we're supposed to know how your table looks like?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Code tags, use the [code][/code] tags!
    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.

  6. #6
    Registered User
    Join Date
    Aug 2006
    Posts
    4

    Question

    here's my table creation statement:

    Code:
    "create table `channel`(`id` int(11) auto_increment PRIMARY KEY,`frequency` int(11) ,`mod` int(11))";

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So what exactly are you asking that can't be fixed by
    a) reading http://dev.mysql.com/doc/refman/5.0/en/c.html
    b) trying some of the examples provided
    c) adapting them to refer to your table name and field names
    d) writing a for loop to iterate over your input array to insert data into the table.
    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.

  8. #8
    Registered User wintellect's Avatar
    Join Date
    Mar 2006
    Posts
    24
    hint:
    Code:
    int mysql_query(MYSQL *mysql, const char *query)
    
    Executes the SQL query pointed to by the null-terminated string query. Normally, the string must consist of a single SQL statement and you should not add a terminating semicolon (‘;’) or \g to the statement.
    If you know SQL and C, the rest is easy! And don'r forget to commit your INSERT !

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    4

    Smile

    yeah..
    that works..
    thanks..
    fazz

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C API for MySQL
    By gvector1 in forum C Programming
    Replies: 10
    Last Post: 03-16-2011, 02:07 AM
  2. MySQL C API Header File Problems
    By WarrenKeyes3 in forum C Programming
    Replies: 3
    Last Post: 03-26-2009, 02:26 PM
  3. MySQL C API or ODBC?
    By serfurj in forum C Programming
    Replies: 3
    Last Post: 02-01-2005, 07:32 PM
  4. no output with MySQL C API
    By trekker in forum C Programming
    Replies: 1
    Last Post: 05-22-2003, 01:27 PM
  5. MySQL C API Forum
    By rotis23 in forum Linux Programming
    Replies: 2
    Last Post: 12-13-2002, 03:16 AM