[ILUG-Cochin.org] Postgresql Help
Saju M
sajuptpm at gmail.com
Tue Mar 31 13:07:19 IST 2009
How can insert values from variables to Postgres database.
#include<stdio.h>
#include "/usr/include/libpq-fe.h"
void main()
{
PGconn *conn;
PGresult *res;
int id;
char name[20];
char *qur;
conn =
PQsetdbLogin("127.0.0.1","5432",NULL,NULL,"postgres","postgres",NULL);
if(PQstatus(conn)==CONNECTION_OK)
{
printf("Connection Established\n\n");
printf("Enter the ID: \n");
scanf("%d",&id);
printf("Enter the NAME: \n");
scanf("%s",&name);
*qur="insert into table values(3,'pkv')";
res = PQexec(conn,qur);
// res = PQexec(conn,"Select * from table1");
// printf("ID : %s\t",PQgetvalue(res,0,0));
// printf("Name : %s",PQgetvalue(res,0,1));
PQfinish(conn);
}
else
{
printf("Connection Failed\n");
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ilug-cochin.org/pipermail/mailinglist_ilug-cochin.org/attachments/20090331/750e4968/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: database2.c
Type: text/x-csrc
Size: 718 bytes
Desc: not available
URL: <http://ilug-cochin.org/pipermail/mailinglist_ilug-cochin.org/attachments/20090331/750e4968/attachment.bin>
More information about the Mailinglist
mailing list