配置环境:

MFC连接postgre数据库,mfcpostgre数据库

安插环境:

    include:libpq-fe.h文件

    lib:libpq.lib文件

    dll:libeay32.dll,libiconv-2.dll,libintl-8.dll,libpq.dll,ssleay32.dll三个公文

一而再代码: 

PGresult *res;//存放结果
PGconn *m_conn;

//连接数据库

m_conn = PQsetdbLogin(ip,port,””,””,dbname,user,password);

PQsetClientEncoding(m_conn,”GBK”);
if (PQstatus(m_conn) != CONNECTION_OK)
{
//连接数据库失利,就输出失败原因
CString strErr;
strErr.Format(_T(“连接数据库失利
[%s]”),CString(PQerrorMessage(m_conn)));
AfxMessageBox(strErr);
PQfinish(m_conn);
return;
}

//定义数据库查询语句得到查询结果
string strsql = “select * from tb_way_performance where
sp_way_id>0” ;
res = PQexec(m_conn, strsql.c_str());

//依据字段值得到字段way_id所在列

int col_way_id = PQfnumber(res,”way_id”);

//获取列值col_way_id 和行值i得到单元格的值

CString str_way_id(PQgetvalue(result,i,col_way_id));

 

末尾附带libpq连接postgre数据库的api文档

配置环境:
include:libpq-fe.h文件 lib:libpq.lib文件
dll:libeay32.dll,libiconv-2.dll,libintl-8.dll,libpq.dll,s…

布置环境:

配备环境:

    include:libpq-fe.h文件

    include:libpq-fe.h文件

    include:mysql.h文件

    lib:libpq.lib文件

    lib:libpq.lib文件

    lib:libmysql.lib文件

    dll:libeay32.dll,libiconv-2.dll,libintl-8.dll,libpq.dll,ssleay32.dll三个文本

    dll:libeay32.dll,libiconv-2.dll,libintl-8.dll,libpq.dll,ssleay32.dll七个文件

    dll:;libmysql.dll文件

接连代码: 

连接代码: 

连天代码:

PGresult *res;//存放结果
MFC连接Mysql数据库执行查询和插入。PGconn *m_conn;

PGresult *res;//存放结果
PGconn *m_conn;

MYSQL m_sqlCon;
MYSQL_RES *m_res;
MYSQL_ROW row;

//连接数据库

//连接数据库

//起头化数据库
mysql_init(&m_sqlCon);
// 设置连接数据库字符串
CString conn_ip,conn_port,conn_dbname,conn_user,conn_password;

m_conn = PQsetdbLogin(ip,port,””,””,dbname,user,password);

m_conn = PQsetdbLogin(ip,port,””,””,dbname,user,password);

if(!mysql_real_connect(&m_sqlCon,conn_ip,conn_user,conn_password,conn_dbname,int_port,NULL,0))
{
  AfxMessageBox(_T(“访问数据库失利!”));
  return;
}

PQsetClientEncoding(m_conn,”GBK”);
if (PQstatus(m_conn) != CONNECTION_OK)
{
//连接数据库战败,就输出战败原因
CString strErr;
strErr.Format(_T(“连接数据库战败
[%s]”),CString(PQerrorMessage(m_conn)));
AfxMessageBox(strErr);
PQfinish(m_conn);
return;
}

PQsetClientEncoding(m_conn,”GBK”);
if (PQstatus(m_conn) != CONNECTION_OK)
{
//连接数据库退步,就输出战败原因
CString strErr;
strErr.Format(_T(“连接数据库战败
[%s]”),CString(PQerrorMessage(m_conn)));
AfxMessageBox(strErr);
PQfinish(m_conn);
return;
}

mysql_query(&m_sqlCon,”SET NAMES
‘GB2312′”);//消除从数据库中读取数据明代字乱码突显的标题  

//定义数据库查询语句得到查询结果
string strsql = “select * from tb_way_performance where
sp_way_id>0” ;
res = PQexec(m_conn, strsql.c_str());

//定义数据库查询语句拿到查询结果
string strsql = “select * from tb_way_performance where
sp_way_id>0” ;
res = PQexec(m_conn, strsql.c_str());

//定义sql语句

//根据字段值拿到字段way_id所在列

//依照字段值拿到字段way_id所在列

const char *sql = “select * from table”;

int col_way_id = PQfnumber(res,”way_id”);

int col_way_id = PQfnumber(res,”way_id”);

//执行查询

//获取列值col_way_id 和行值i得到单元格的值

//获取列值col_way_id 和行值i得到单元格的值

m_res = mysql_store_result(&m_sqlCon);

CString str_way_id(PQgetvalue(result,i,col_way_id));

CString str_way_id(PQgetvalue(result,i,col_way_id));

//如果为空则再次回到

 

 

if(NULL == m_res)
{ return; }

末段附带libpq连接postgre数据库的api文档

最后附带libpq连接postgre数据库的api文档

//重复读取行,把数量放入列表中,直到row为NULL

while (row = mysql_fetch_row(m_res)) 
{
  for (int rols = 0; rols < 2; rols++)
澳门金沙国际,  {
    CString myreaddata(row[rols]);
    list.AddString(myreaddata);
  }
}

//执行插入

const char *sql = “insert into tb_rdchange(way_id,sp_way_id)
values(4,4)”;
if(mysql_real_query(&m_sqlCon, sql,(unsigned long)strlen(sql)))
{
  return;
}

 

相关文章