By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,655 Members | 1,860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,655 IT Pros & Developers. It's quick & easy.

Internal Server Error in connecting Postgresql Server

P: 3
Hello,

I wrote C program for connecting to postgresSQL server to retrieve data from the postgres database. The program is:

#include <stdio.h>
#include <stdlib.h>
#include "libpq-fe.h"

int
Search(inStruct Sentries)
{
char state_code[3];
char query_string[256];
PGconn *conn;
PGresult *res;
int i;

conn = PQconnectdb("host=127.0.0.1 dbname=ontology user=postgres password=postgres port=5432");

if (PQstatus(conn) == CONNECTION_BAD)
{
printf("Content-type: text/html%c%c",10,10);fflush(stdout);
printf("<html>");
printf("<body background=\"%s/background.gif\">", webPath);
fprintf(stderr, "Connection to database failed.\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
exit(1);
printf("</body></html>");
}


sprintf(query_string,
"SELECT term_name \
FROM term \
WHERE term_id = '%s'", Sentries->entries[1].val);

res = PQexec(conn, query_string);

if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
printf("Content-type: text/html%c%c",10,10);fflush(stdout);
printf("<html>");
printf("<body background=\"%s/background.gif\">", webPath);
fprintf(stderr, "SELECT query failed.\n");
PQclear(res);
PQfinish(conn);
exit(1);
printf("</body></html>");
}

for (i = 0; i < PQntuples(res); i++)
printf("%s\n", PQgetvalue(res, i, 0));
printf("Content-type: text/html%c%c",10,10);fflush(stdout);
printf("<html>");
printf("<body background=\"%s/background.gif\">", webPath);
printf("<br><br><font>Term Name: </font><font color=#FF0000>%s</font>",res);
printf("</body></html>");

PQclear(res);

PQfinish(conn);

return 0;
}

When I run this program, I got the Internal Server Error. What could be the problem here? Can anyone help me to solve this problem.
Really appreciate for the helping hands.

With Regards,
SYT
Mar 11 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.