mySQL and C question

Discussion in 'C Programming' started by QQ, May 31, 2005.

  1. QQ

    QQ Guest

    Hello

    I am accessing a mySQL database through C.
    I am reading some books and testing the program.
    However, I didn't find some explanations that I am curious.
    My question is:

    If I access the database through C, do I need to create
    a database at mySQL first and create table by mySQL too.
    Then I can use C to insert, update, delete the rows.

    Or can I do all the things through C such as create a database, insert
    and update..... ? If I can, how can I do it?

    Thanks a lot!
    QQ, May 31, 2005
    #1
    1. Advertising

  2. QQ

    Malcolm Guest

    "QQ" <> wrote
    >
    > I am accessing a mySQL database through C.
    > Or can I do all the things through C such as create a database, insert
    > and update..... ? If I can, how can I do it?
    >

    As far as C is concerned sql is just another third party api. It is rather
    powerful because it can access huge databases very quickly, but still just a
    normal set of function calls.
    It would be very surprising if your implementation didn't give facilties for
    creating and editing databases, though you might need permissions to edit
    existing databases. However the details aren't on topic here.
    Malcolm, May 31, 2005
    #2
    1. Advertising

  3. >If I access the database through C, do I need to create
    >a database at mySQL first and create table by mySQL too.
    >Then I can use C to insert, update, delete the rows.
    >
    >Or can I do all the things through C such as create a database, insert
    >and update..... ? If I can, how can I do it?


    Using the MySQL C API, you can generate the queries as C strings
    and then run them with mysql_query(), assuming that the MySQL login
    you are using from C has sufficient privileges to do what you want
    it to do (create databases, create tables, alter tables, drop
    databases, etc.) sprintf() might be convenient to generate queries
    with values substituted into the query.

    Gordon L. Burditt
    Gordon Burditt, May 31, 2005
    #3
  4. QQ

    SM Ryan Guest

    # If I access the database through C, do I need to create
    # a database at mySQL first and create table by mySQL too.
    # Then I can use C to insert, update, delete the rows.

    The MySQL interface just opens a channel to the server through which you
    send whatever queries you wish, including create database or table, or
    grants, selects, inserts, etc, as character strings. The server has to
    be running.

    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    The whole world's against us.
    SM Ryan, Jun 1, 2005
    #4
  5. QQ

    pete Guest

    SM Ryan wrote:
    >
    > # If I access the database through C, do I need to create
    > # a database at mySQL first and create table by mySQL too.
    > # Then I can use C to insert, update, delete the rows.


    Your squirrel is off topic.

    --
    pete
    pete, Jun 1, 2005
    #5
  6. QQ

    Philip Paeps Guest

    QQ <> wrote:
    > If I access the database through C, do I need to create a database at mySQL
    > first and create table by mySQL too. Then I can use C to insert, update,
    > delete the rows.
    >
    > Or can I do all the things through C such as create a database, insert and
    > update..... ? If I can, how can I do it?


    You can simply use MySQL API calls to do all that from within your C programs.
    After all, the MySQL tools are also written in C, using the same library.

    The MySQL C API documentation is very complete, and can be found here:

    <http://dev.mysql.com/doc/mysql/en/c.html>

    Basically, you just have to make a connection to your MySQL server, properly
    authenticated so it's allowed to do the things you want to do, then you'll
    have to prepare a statement ('query') of the things you want done, and fire it
    off to the server over the connection you opened. Check errors, disconnect.

    - Philip

    --
    Philip Paeps Please don't email any replies
    I follow the newsgroup.

    It is ok to be ignorant in some areas,
    but some people abuse the privilege.
    Philip Paeps, Jun 1, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeffrey H. Coffield
    Replies:
    1
    Views:
    1,855
  2. Roedy Green
    Replies:
    0
    Views:
    1,472
    Roedy Green
    Jul 23, 2009
  3. dave
    Replies:
    4
    Views:
    1,366
    Steve Holden
    Nov 18, 2010
  4. bin liu
    Replies:
    1
    Views:
    128
    Curt Hibbs
    Dec 22, 2004
  5. Mark Meijer

    mySQL Ruby Gem and MAMP mySQL

    Mark Meijer, Feb 2, 2008, in forum: Ruby
    Replies:
    3
    Views:
    176
    louis
    Feb 3, 2008
Loading...

Share This Page