471,887 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

Internal Server Error in connecting Postgresql Server

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
0 2689

Post your reply

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

Similar topics

reply views Thread by Terry Ladouceur | last post: by
reply views Thread by Bill J. | last post: by
2 posts views Thread by Andy Chen | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.