.php脚本以显示mysql内容

8yoxcaq7  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(429)

嘿,
我对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文件吗?
我的主人有什么问题吗?
谢谢您

luaexgnf

luaexgnf1#

很可能你的php文件正在被缓存。尝试将这些行添加到.php文件的开头。

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); 
header("Expires: Sat, 10 Jul 1990 05:00:00 GMT"); // Date must be in the past

然后重新启动服务器

相关问题