In my react native application, I want show data that I get from my sql server using php.
The problem is my php file works fine( when I try it in postman or any browser) but when I run the application in my phone I got nothing, what can be the cause??
import React, { useEffect, useState } from 'react';
import { ActivityIndicator, FlatList, Text, View } from 'react-native';
export default App = () => {
const [isLoading, setLoading] = useState(true);
const [data, setData] = useState([]);
useEffect(() => {
fetch('http://192.168.1.10/ment.php')
.then((response) => response.json())
.then((json) => setData(json.movies))
.catch((error) => console.error(error))
.finally(() => setLoading(false));
}, []);
return (
<View style={{ flex: 1, padding: 24 }}>
{isLoading ? <ActivityIndicator/> : (
<FlatList
data={data}
keyExtractor={({ id }, index) => id}
renderItem={({ item }) => (
<Text>{item.MOIS}</Text>
)}
/>
)}
</View>
);
};
And this is my php file that shows 5 months from my DB
<?php
include 'serverName.php';
$connectionInfo=array("Database"=>"Net","UID"=>"s","PWD"=>"123");
$conn=sqlsrv_connect($serverName,$connectionInfo);
$sql = "select TOP 5 MOIS from Dyn_Encaissement " ;
$stmt = sqlsrv_query( $conn, $sql );
while( $row[] = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ){
$Item = $row;
$json = json_encode($Item);
}
echo $json;
?>