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();
}
}