我通过php文件从数据库中检索了最后10个值,因为我试图将这10个值一个接一个地传递到文本文件中,但是这里的问题是只有一个最后一个值传递到了文本文件中。 如果我在终端中编译该特定php文件,则显示最后10个值,但未复制到文本文件中,仅复制一个值。
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT pass FROM milestones ORDER BY id DESC LIMIT 10";
$passres = $conn->query($sql);
if ($passres->num_rows > 0) {
// output data of each row
while($row = $passres->fetch_assoc()) {
// echo "pass: " . $row["pass"]. "";
$accessword= $row["pass"];
echo $accessword;
//exec ('php create_lic.php', $accessword);
file_put_contents ('test.txt', $accessword);
//echo stream_copy_to_stream($accessword) . " bytes copied to test.txt\n";
}
}
else {
echo "0 results";
}
$conn->close();
?>
I expect what are all the values displaying in the terminal it should be copy into the text file