0

I have a wamp server on my local computer. I am able to get the data using PHP script in my browser;

$mysqli = new mysqli("localhost", "root", "", "q");
/* Select queries return a resultset */
if ($result = $mysqli->query("select * from Institution LIMIT 10")) {
    printf("Select returned %d rows.<br />", $result->num_rows);
}

while ($row = $result->fetch_row()) {
    printf("idInstitution is %s, %s, %s, %s<br />", $row[0], $row[3], $row[8], $row[9]);

    $output[] = $row;
}

$result->close();

print(json_encode($output));// this will print the output in json

mysqli_close($mysqli);

On my browser I typed the following URL http://localhost/q/myfile1.php and the output is as follows:

Browser output

Select returned 4 rows.
idInstitution is 4, ???? ?????, 60, True
idInstitution is 5, ???? ?????, 0, True
idInstitution is 6, ????? ?????, 45, False
idInstitution is 7, test, , False
[
  ["4","0","0","???? ????",null,null,null,null,"60","True",null],
  ["5","0","0","???? ?????",null,null,null,null,"0","True",null],
  ["6","0","0","????? ?????",null,null,null,null,"45","False",null],
  ["7","0","0","test",null,null,null,null,null,"False",null]
]

I want to be able to get the last row ($output) in my android application. How do I do it?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Zvi
  • 2,354
  • 2
  • 26
  • 37
  • Do you not know how to process and array in java OR do you now know how to launch the script from java OR What is actually your question??? – RiggsFolly Aug 16 '15 at 00:42
  • My question was that my application could not connect to the wamp server. I was getting exception. I was trying all kind of solution I found on the net, such as changing the url or using strictMode. Eventually I found out that the problem was that I was executing the http request in my main thread. When I moved it to a background thread the connection to the wamp server was successful, and I got the data I expected. – Zvi Aug 16 '15 at 22:04
  • I was too optimistic. It worked on the emulator but on a real phone I still get the error "connection refused" – Zvi Aug 16 '15 at 23:03
  • Finally found the solution - need to change properly the httpd.conf as explained in http://stackoverflow.com/questions/19132059/how-to-allow-remote-access-to-my-wamp-server-for-mobileandroid – Zvi Aug 17 '15 at 23:48

1 Answers1

0

Problem solved - see my edit. All I needed is to move the http code to a background thread.

Zvi
  • 2,354
  • 2
  • 26
  • 37
  • I was too optimistic. It worked on the emulator but on a real phone I still get the error "connection refused" – Zvi Aug 16 '15 at 23:04