我正在使用libpqxx通過創建一個類來連接到postgres數據庫。使用libpqxx連接到Postgres數據庫
class databaseConnection
{
public:
pqxx::connection* conn;
void SetConnection(){
conn=new pqxx::connection(
"username=temp "
"host=db.corral.tacc.utexas.edu "
"password=timelione "
"dbname=temp");
}
void Disconnect(){
conn->disconnect();
}
pqxx::result query(std::string strSQL){
//SetConnection();
pqxx::work trans(*conn,"trans");
pqxx::result res=trans.exec(strSQL);
trans.commit();
return res;
}
};
int main()
{
databaseConnection* pdatabase;
pdatabase->SetConnection();
return 0;
}
我得到的錯誤,說
terminate called after throwing an instance of 'pqxx::broken_connection'
what(): invalid connection option "database"
誰能幫助我嗎?
感謝
爲什麼你不使用libpq的? –
@Gaurav有丹尼爾的回答對你有幫助嗎?如果是這樣,請接受它。我面臨類似的問題,如果你不接受它,我們大多數新用戶不會知道這是否是一個解決方案。畢竟,他花時間來幫助你,你應該至少感謝。 – itsols