mySQL and C question

Q

QQ

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!
 
M

Malcolm

QQ said:
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.
 
G

Gordon Burditt

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
 
S

SM Ryan

# 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.
 
P

pete

SM said:
# 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.
 
P

Philip Paeps

QQ said:
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
(e-mail address removed) I follow the newsgroup.

It is ok to be ignorant in some areas,
but some people abuse the privilege.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top