469,275 Members | 1,718 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

database connectivity through C program

Hi to all,
Can it is possible to connect to the databse like postgre or mysql
through a C programm?

I know the basics of C and I have developed a small program which uses
a file for the repositary of the data.But I want to use a database for
this, insted of file.

If possible please give some Code snippets for the connectivity as well
as how to run the queries.

Thanks Junaid

Nov 14 '05 #1
3 1901

"junaid" <ju*********@yahoo.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi to all,
Can it is possible to connect to the databse like postgre or mysql
through a C programm?

I know the basics of C and I have developed a small program which uses
a file for the repositary of the data.But I want to use a database for
this, insted of file.

If possible please give some Code snippets for the connectivity as well
as how to run the queries.

Thanks Junaid


Database connectivity isn't part of the C language per-se, so isn't really
on-topic for this group.
But yes, you can certainly use C to connect to PostgreSQL or MySQL.
You need to read the documentation for PostgreSQL and/or MySQL, where they
show how, and show examples.
Nov 14 '05 #2
"junaid" <ju*********@yahoo.com> writes:
Can it is possible to connect to the databse like postgre or mysql
through a C programm?


Undoubtedly. Check the documentation of whatever database you're
using, or post to a newsgroup that deals with databases. It can't be
done in *portable* C, so we can't discuss it here.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #3

"junaid" <ju*********@yahoo.com> wrote

Can it is possible to connect to the databse like postgre or mysql
through a C programm?
Normally by calling library functions supplied by the databse vendor, or
maybe third parties, just as you would any other function.
I know the basics of C and I have developed a small program which uses
a file for the repositary of the data.But I want to use a database for
this, insted of file.

If possible please give some Code snippets for the connectivity as well
as how to run the queries.

Unfortunately we don't discuss non-ANSI libraries on this ng. However we do
discuss how to use such libraries in a general way.

This would be typical code.

#include <stdio.h>
#include <library_specific_header>

void yourfunction()
{
THEIRTYPE x;
int result;
x = theirfunction("a string parameter");
result = theirotherfunction(x);
printf("Their library gave me this result %d\n", result)'
}

When you compile, some compilers will ask you to link the library, which may
involve knowing where it is physically kept and what the filename is. Others
will do this automatically.
Nov 14 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by SectorUnknown | last post: by
2 posts views Thread by Rosy Moss | last post: by
3 posts views Thread by Niks | last post: by
47 posts views Thread by Ivan Weiss | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.