Hey guys!!
im trying to build an android app and i tried using this php to connect to mysql and return json. but the server doesnt return anything. is there something wrong!?
[php] <?php
if($_SERVER[“REQUEST_METHOD”]==“POST”){
include ‘connection.php’;
getInsurances();
}
function getInsurances()
{
global $connect;
$query = " Select * FROM insurance; ";
$result = mysqli_query($connect, $query);
$number_of_rows = mysqli_num_rows($result);
$temp_array = array();
if($number_of_rows > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$temp_array[] = $row;
}
}
header('Content-Type: application/json');
echo json_encode($temp_array);
mysqli_close($connect);
} [/php]
my connection.php is this but with the right data
[php]<?php
define(‘hostname’, ‘xxxxxxxx’);
define(‘user’, ‘xxxxxxxx’);
define(‘password’, ‘xxxxxxxx’);
define(‘databaseName’, ‘xxxxxxx’);
$connect = mysqli_connect(hostname, user, password, databaseName);
?> [/php]
it should return a json with a list of insurance companies.
i need help thanks in advance!!