嘿,
我对php很陌生,下面的脚本有问题。其思想是从数据库中读取内容并以json格式显示。我在这页上找到了:
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);
?>
它工作得很好,显示了我数据库的所有内容。
问题是,如果我(通过phpmyadmin)更改了数据库,php脚本仍然像以前一样显示内容。
另一个奇怪的行为是,例如,如果我重命名php。脚本从“service.php”到“service1.php”并加载它,它将反映对数据库所做的更改。
我的问题是:
php脚本是否有可能改进?
关于php/update,有什么我不明白的吗?
我必须以某种方式启动php文件吗?
我的主人有什么问题吗?
谢谢您
1条答案
按热度按时间luaexgnf1#
很可能你的php文件正在被缓存。尝试将这些行添加到.php文件的开头。
然后重新启动服务器