database connectivity through C program

J

junaid

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
 
C

Charles F McDevitt

junaid said:
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.
 
K

Keith Thompson

junaid said:
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.
 
M

Malcolm

junaid said:
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.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top