#include #include #include const char *DBNAME = "clientWebSite";const char *DBTABLE = "products";const char *DBHOST = "backend.company.com";const char *DBUSER = "mysqluser";const char *DBPASSWD = "abigsecret":int main() { try { //open the database connection and query Connection con(DBNAME, DBHOST, DBUSER, DBPASSWD); Query query = con.query(); //write valid sql code to the query object query << "select * from " << DBTABLE; //run the query and store the results Result res = query.store(); //write out the html table header cout << "<table border=4>/n"; cout << "<th>Product Id <th width=200>Description" << "<th>Price ($)" << endl; Result::iterator curResult; Row row; //iterate over each result and put it into an html table for (curResult = res.begin(); curResult != res.end(); curResult++) { row = *curResult; cout << "<tr><td align=center>" << row[0] << "<td>" << row[1] << "<td>" << row[2] << endl; } cout << "</table>" << endl; } catch (BadQuery er) { // handle a bad query (usually caused by a sql syntax error) cerr << "Error: " << er.error << endl; return -1; } catch (BadConversion er) { //handle conversion errors out of the database as well cerr << "Error: Can't convert /"" << er.data << "/" to a /"" << er.type_name << "/"." << endl; return -1; } return 0;}
|