【win10 c++连接PostgreSQL详细记录-增删改查】

【win10 c++连接PostgreSQL详细记录-增删改查】

有网友问到了,连接完数据库该如何查询,我也一起学习记录一下!

谢谢关注!!
在这里插入图片描述

一、数据库创建一个表格格式

示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。
新增一些数据进去
在这里插入图片描述

二、使用步骤

1.查询数据

代码如下(示例):

void printData(PGconn* conn, string tableName) {
   
    std::string query = "SELECT * FROM " + tableName;
    PGresult* res = PQexec(conn, query.c_str());

    if (PQresultStatus(res) != PGRES_TUPLES_OK) {
   
        std::cerr << "Query failed: " << PQerrorMessage(conn) << std::endl;
        PQclear(res);
        return;
    }

    int numRows = PQntuples(res);
    int numCols = PQnfields(res);

    for (int row = 0; row < numRows; ++row) 
    {
   
        for (int col = 0; col < numCols; ++col) 
        {
   
            string celldata = UTF8ToGBK(PQgetvalue(res, row, col));
            std::cout << celldata << "\t";
        }
        std::cout << std::endl;
    }

    PQclear(res);
}

#include <iostream>
#include "libpq-fe.h"
#include<Windows.h>
#include <string>
using namespace std;

int main()
{
   
	PGconn* m_conn ;
	//连接方式1:
	const char* conninfo = "host = 192.168.222.131 port = 5432 dbname = postgres user = postgres password = YAQyaq123";
	m_conn = PQconnectdb(conninfo)
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小余是条鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值