MFC connects to the postgre database and the mfcpostgre Database
Configuration environment:
Include: libpq-fe.h files
Lib: libpq. lib File
Dll: libeay32.dll, libiconv-2.dll, libintl-8.dll, libpq. dll, ssleay32.dll five files
Connection code:
PGresult * res; // store the result
PGconn * m_conn;
// Connect to the database
M_conn = PQsetdbLogin (Ip, port, "", "", dbname, user, password);
PQsetClientEncoding (m_conn, "GBK ");
If (PQstatus (m_conn )! = CONNECTION_ OK)
{
// If the connection to the database fails, the cause of the failure is output.
CString strErr;
StrErr. Format (_ T ("failed to connect to database [% s]"), CString (PQerrorMessage (m_conn )));
AfxMessageBox (strErr );
PQfinish (m_conn );
Return;
}
// Define the database query statement to obtain the query result
String strsql = "select * from tb_way_performance where sp_way_id> 0 ";
Res = PQexec (m_conn, strsql. c_str ());
// Obtain the column where the field way_id is located based on the field value
Int col_way_id = p1_number (res, "way_id ");
// Obtain the value of the cell by col_way_id and row I.
CString str_way_id (PQgetvalue (result, I, col_way_id ));
Finally, it comes with the api documentation for connecting libpq to the postgre database.
Http://www.kuqin.com/postgreSQL8.1_doc/libpq.html