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 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧