MFC connects to the postgre database and the mfcpostgre Database

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.