Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to connect php and wamp in android
    primarykey
    data
    text
    <p>I want to have some data on adatabase and my application retrieves data from there. I am beginner and i do not know how to create my databas, although I have written the php script and the java code for getting those results. So I need your help in creating that databae. I am using WAMP and I have created a database. My problem is what will be the arguments of those calls:</p> <pre><code>mysql_connect("127.0.0.1","root","xxpasswordxx"); </code></pre> <p>and of this one:</p> <pre><code>public static final String KEY_121 = "http://xx.xx.xxx.xxx/hellomysql/mysqlcon.php"; </code></pre> <p>I read somewhere that here I maust place 10.0.0.2 and my directory under C:\wamp\www where my php file is stored.</p> <p>Edit: code added</p> <p>This is my android code:</p> <pre><code>@SuppressWarnings("null") private void DoMain() { setContentView(R.layout.main); // Set the text and call the connect function. //call the method to run the data retreival getServerData(KEY_121); } public static final String KEY_121 ="http://10.0.2.2:8888/example.php"; //what in here?? private String getServerData(String returnString) { InputStream is = null; String result = ""; //the year data to send ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(); nameValuePairs.add(new BasicNameValuePair("year","1970")); //http post try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(KEY_121); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); }catch(Exception e){ Log.e("log_tag", "Error in http connection "+e.toString()); } //convert response to string try{ BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result=sb.toString(); }catch(Exception e){ Log.e("log_tag", "Error converting result "+e.toString()); } //parse json data try{ JSONArray jArray = new JSONArray(result); for(int i=0;i&lt;jArray.length();i++){ JSONObject json_data = jArray.getJSONObject(i); Log.i("log_tag","id: "+json_data.getInt("id")+ ", name: "+json_data.getString("name")+ ", sex: "+json_data.getInt("sex")+ ", birthyear: "+json_data.getInt("birthyear") ); //Get an output to the screen returnString += "\n\t" + jArray.getJSONObject(i); } }catch(JSONException e){ Log.e("log_tag", "Error parsing data "+e.toString()); } return returnString; } </code></pre> <p>and this is my php file</p> <pre><code>&lt;?php mysql_connect("127.0.0.1","root","xxpasswordxx"); //what in here?? mysql_select_db("peopledata"); $q=mysql_query("SELECT * FROM people WHERE birthyear&gt;'".$_REQUEST['year']."'"); while($e=mysql_fetch_assoc($q)) $output[]=$e; print(json_encode($output)); mysql_close(); </code></pre> <p>?></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload