#include <iostream>
#include <string>
#include <mysql++.h>
using namespace std;
using namespace mysqlpp;
int main (int argc, char * const argv[])
{
string database_name = "db_rev_4";
string ip_address = "x.x.x.x";
string username = "username";
string password = "password";
string error_msg;
try
{
Result client_id_result;
cout << "Attempting to connect to the database...";
Connection m_connection(database_name.c_str(),
ip_address.c_str(),
username.c_str(),
password.c_str(),
3306,
false,
15);
cout << "connected to the database" << endl;
Query client_id_query = m_connection.query();
client_id_query <<
"select client_id from clients where client_user_name ="
<< quote_only << username << " and client_password ="
<< quote_only << password;
cout << "Query created: ";
cout << client_id_query.preview() << endl;
m_connection.close();
}
catch (exception &e)
{
cout << "exception occurred..." << endl;
error_msg = e.what();
cout << error_msg;
}
catch (...)
{
error_msg = "Unknown exception";
cout << error_msg << endl;
}
return 0;
}