dpgu5074 2013-07-25 11:12
浏览 81

使用从Android应用程序通过PHP插入的数据连接到PostgreSQL数据库时出错

My current android application allows user to key in chat room name where I'll be utilizing the name stored as the database name. Hence the name stored will be used to connect to the database using PHP web service. I understand that there're some solutions which is editing the pg_ident.conf file, allowing www-data to be recognized as one of the users to access the database. However, I'm hoping to have a better solution. Thanks in advance for the help given.

This is the error message I got

Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server: FATAL: role "www-data" does not exist.

PHP code (blabla.php)

<?php
 $host = "localhost";
 $user = "bbcc";
 $db=$_POST['name'];
 $passwd = "abc";

 $con = pg_connect("host=$host dbname=$db user=$user password=$passwd") or die ("Could not connect to server
" . pg_last_error());
?>

Java code snippet

   private void valid() { 

        String room = "abcd";
        try{
             HttpParams params = new BasicHttpParams();
             HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
             HttpConnectionParams.setSoTimeout(params, 30 * 1000);
             HttpClient httpclient = new DefaultHttpClient(params);
             HttpPost httppost = new HttpPost("http://111.11.111.000/script/blabla.php");
             List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();    
             nameValuePairs.add(new BasicNameValuePair("name", room));
             httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
             HttpResponse response = httpclient.execute(httppost);
        }catch(Exception e){
            e.printStackTrace();
        }
  }
  • 写回答

1条回答 默认 最新

  • doubangzhang6992 2013-07-25 12:59
    关注

    check this settings pg_hba.conf

    This file controls: which hosts are allowed to connect, how clients are authenticated, which PostgreSQL user names they can use, which databases they can access. Records take one of these forms:

    local      DATABASE  USER  METHOD  [OPTIONS]
    host       DATABASE  USER  CIDR-ADDRESS  METHOD  [OPTIONS]
    hostssl    DATABASE  USER  CIDR-ADDRESS  METHOD  [OPTIONS]
    hostnossl  DATABASE  USER  CIDR-ADDRESS  METHOD  [OPTIONS]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据