Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
返回PGconn结构类型“;postgresql结构类型“;C中的指针_C_Postgresql_Pg - Fatal编程技术网

返回PGconn结构类型“;postgresql结构类型“;C中的指针

返回PGconn结构类型“;postgresql结构类型“;C中的指针,c,postgresql,pg,C,Postgresql,Pg,为了连接到Postgresql数据库,我有这样一个函数: PGconn *connect() { PGconn *conn; //Creating a connection to database conn = PQconnectdb("dbname=... host=... user=... password=..."); //Check connection status if (PQstatus(conn) == CONNECTION_BAD) {

为了连接到Postgresql数据库,我有这样一个函数:

PGconn *connect()
{
    PGconn *conn;

    //Creating a connection to database
    conn = PQconnectdb("dbname=... host=... user=... password=...");
    //Check connection status
    if (PQstatus(conn) == CONNECTION_BAD) {
        printf("We were unable to connect to the database\n");
        return 0;
    }

    return conn;
}
我想返回“conn”值,但得到了分段错误。如何在此处返回“conn”值?

无法使用和在本地环境中复制(未安装PostgreSQL,连接失败)。