zoukankan      html  css  js  c++  java
  • 使用VC6.0 连接PostgreSQL数据库

     我使用的版本是

    VC6 + postgresql-8.4.8-1-windows-binaries 

    使用这个版本的好处是解压就可以获得一些文件支持,

    pgsql\include

    pgsql\lib 

    依赖文件在bin下有:

    如果就是演示我下面的例子: 需要 

        comerr32.dll

        gssapi32.dll

        iconv.dll
        k5sprt32.dll
        krb5_32.dll
        libeay32.dll
        libiconv-2.dll
        libintl-8.dll
        libpq.dll
        libxml2.dll
        libxslt.dll
        msvcr71.dll
        ssleay32.dll
        zlib1.dll

    解压后这2个目录有你要的文件(开发用的)


    下面上代码吧

    // pgDemo.cpp : Defines the entry point for the console application.
    //


    #include "stdafx.h"


    #include "libpq-fe.h"


    int main(int argc, char* argv[])
    {
      PGconn * connection; 
      /** 顺带解释下,链接字符串的构成
      Table 8.2. Connection Attributes Connect-String Keyword
      Environment Variable Example
      user PGUSER user=korry
      password PGPASSWORD password=cows
      dbname PGDATABASE dbname=accounting 
      host PGHOST host=jersey
      hostaddr PGHOSTADDR hostaddr=127.0.0.1
      service PGSERVICE service=accounting 
      port PGPORT port=5432 
      **/
      
      // 用下面这个是因为不需要SSL的支持,加上IP就需要了
      // 注意大小写敏感
      connection = PQconnectdb( "dbname=mydb user=Eagle password=123456");  
           
      if ( PQstatus(connection) != CONNECTION_OK )
      {
      printf("%s \n", PQerrorMessage(connection) );
      }
      else
      {
      printf("connect is ok \n");
      }
      PQfinish( connection);
      
      return 0;
    }

    运行结果如下:

    ( "dbname=mydb user=Eagle password=123456");   使用这个参数的意: 自己的数据库名字: mydb 下面的应该不用解释了 地球人都知道

    运行截图附上: 



  • 相关阅读:
    Bitstream or PCM?
    centos7安装Redis-3.2.8
    【生肉】【不义联盟
    ES6中Map数据结构学习笔记
    机器学习基石入门
    2019/5/9 长难句
    文件遍历选取脚本
    [JS奇怪的世界]No.55 危險小叮嚀:陣列與for in
    OpenGL Panorama Player
    吴裕雄--天生自然MySQL学习笔记:MySQL 连接
  • 原文地址:https://www.cnblogs.com/eaglezzb/p/4176542.html
Copyright © 2011-2022 走看看