我的perl文件和php文件位於同一個文件夾中。我在Perl調用PHP腳本在cmd中從perl程序運行php腳本
我database.pl腳本
#!/usr/bin/perl
while (2)
{
my $php = `sample.php`;
sleep (10);
}
我sample.php文件
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydb";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE users SET name1='Doe' WHERE id=1";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>
現在,當我運行database.pl
文件,我sample.php
文件是打開在編輯器中每10秒..現在我應該如何讓我的PHP文件運行,以便它應該運行UPDATE查詢。