c++ で CGI プログラムを開発するために、cgicc および mysql++ ライブラリを使用しています。プログラムをコンパイルして実行可能ファイルをビルドすることはできますが、ブラウザで完全な結果を見ることはできません。
Here is the data:
Hello!
select * from table_cities
0
ブラウザ出力の場合に戻る理由と、コンソールの場合に (実際の値) をcout << res.num_rows();
返す理由を理解できませんか?0
18
コンソールで完全な結果を確認できます。
その理由は何でしょうか。コードに何か欠けていますか??
#include <iostream>
#include "cgicc/Cgicc.h"
#include "cgicc/HTTPHTMLHeader.h"
#include "cgicc/HTMLClasses.h"
#include <stdlib.h>
// mysql must come after cgi stuff for some reason
#include <mysql++.h>
using namespace cgicc;
using namespace std;
using namespace mysqlpp;
// Helper function for form text boxes and lists
string getFormString(Cgicc& cgi, char *element)
{
const_form_iterator name = cgi.getElement(element);
if(name != (*cgi).end() && ! name->isEmpty())
return (string)(**name);
else
return (string)"";
}
int main(int argc, char* argv[])
{
Cgicc cgi;
cout << HTTPHTMLHeader() << endl;
//cout << HTMLDoctype(HTMLDoctype::eStrict) << endl;
cout << html() << endl;
cout << head(title("Results")) << endl;
cout << body() << endl;
cout << h1("Here is the data:") << endl;
cout << "Hello!" << p() << endl;
try {
//
Connection conn(false);
conn.connect("ts", "127.0.0.1", "root", "Devesh#1");
string querystr = "select * from table_cities";
cout << querystr << "<br>" << endl;
Query query = conn.query();
query << querystr;
StoreQueryResult res = query.store();
Row row;
StoreQueryResult::iterator iter;
cout << res.num_rows();
cout << table().set("border=1") << endl;
for (iter = res.begin(); iter != res.end(); iter++)
{
row = *iter;
cout << tr() << endl;
cout << td((const char *)row[0]) << endl;
cout << td((const char *)row[1]) << endl;
//cout << td((const char *)row[2]) << endl;
cout << tr() << endl;
}
cout << table() << endl;
}
catch (BadQuery er)
{ // handle any connection or
// query errors that may come up
cerr << "Error: " << er.what() << endl;
return -1;
}
cout << body() << html() << endl;
return 0;
}