CGI+sqlite3

在使用CGI程序与SQLite3数据库进行交互,尝试查询数据时,遇到查询结果未返回到页面的问题。代码中展示了如何打开数据库、执行SQL查询以及设置回调函数来处理查询结果。当GET请求包含"V1"参数时,程序会尝试打开数据库并执行查询,但没有显示查询结果。可能的原因包括查询执行错误或者回调函数处理不当。

gewei daxia:

      dang wo tongcuo CGI chengxu dui SQLITE shujuku jinxing chaxun shi,meiyou chaxun jieguo fanhui dao yemian,zhe shi zenme huishi?chengxu ruxia:

     #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sqlite3.h"

int callback(void *p,int n_column,char **column_value,char **column_name)
{
    int i;
    for(i=0;i<n_column;i++)
    {
        printf("<tr><td width='80' height='30' align='center'>%s</td>",column_value[i]);
        printf("/n");
    }
    printf("</tr>");
    return 0;
}
int main()
{
         sqlite3 *db = NULL;
         char *zErrMsg = 0;
         char **azResult;
         char *sql;
         int rc;
         int nrow = 0, ncolumn = 0, m = 0;
        
     /**************************cgi part************************/
             char *data;

         data=getenv("QUERY_STRING");

         if(strstr(data,"V1"))
         {

           /*********************open database*********************/
              rc = sqlite3_open ("part1.db", &db);
               if (rc)
              {
                   fprintf (stderr, "Can't open database: %s/n", sqlite3_errmsg (db));
                    sqlite3_close (db);
                       exit (EXIT_FAILURE);
              }
              else
                  printf("Content-type: text/html/n/n");
                  printf("<html><head><title>Current State</title></head>/n");
                  printf("<body><h4>Current State As Follows:</h2><pre><hr>/n");
                  printf("Wendu Lists:/n");
                   sql = "SELECT * FROM wendu;";
                   rc=sqlite3_exec(db,sql,callback,NULL,&zErrMsg);

                          sqlite3_close(db);
    }
        printf("</body></html>/n");
         exit(0);

}

 

 

 

guiqiu daan!!!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值