Hej,
I'm quite new to PHP and I have a problem with the following script. The idea is to read content from the database and show it in a json format. I have found this on this page:
https://codewithchris.com/iphone-app-connect-to-mysql-database/
<?php
// Create connection
$con=mysqli_connect("localhost","***","***","***");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// This SQL statement selects ALL from the table 'Locations'
$sql = "SELECT * FROM Locations";
// Check if there are results
if ($result = mysqli_query($con, $sql))
{
// If so, then create a results array and a temporary one
// to hold the data
//$resultArray = array();
// $tempArray = array();
$resultArray = [];
$tempArray = [];
// Loop through each row in the result set
while($row = $result->fetch_object())
{
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Finally, encode the array to JSON and output the results
echo json_encode($resultArray);
}
// Close connections
mysqli_close($con);
?>
It works quite well and displays all the content of my database.
The problem is that if I do changes to my database (by phpMyAdmin) the php script still shows the content like it was before.
Another weird behavior is that, for example if I rename the php. script from "service.php" to "service1.php" and load this it will reflect the changes made to the database.
My questions are:
- Is there an possible improvement to the PHP script?
- Is there something I doesn't understand when it comes to PHP/update?
- Do I have to initiate the PHP file in some way?
- Is there something wrong with my HOST?
Thank you