2016-08-01 77 views
0

我曾與此評論做一個cron作業: 「/home/username/public_html/cron.php」計劃作業PHP腳本錯誤

我的PHP(cron.php)

<?php 

    $server = 'localhost'; 
    $user = 'name'; 
    $pass = 'password'; 
    $dbname = 'dbname'; 

    $conn = new mysqli($server, $user, $pass, $dbname); 

    $sql = "Update table;"; 
    $conn->query($sql); 

    $conn->close(); 
    ?> 

這是錯誤:

/home/username/public_html/cron.php: line 1: ?php: No such file or directory 
/home/username/public_html/cron.php: line 3: =: command not found 
/home/username/public_html/cron.php: line 4: =: command not found 
/home/username/public_html/cron.php: line 5: =: command not found 
/home/username/public_html/cron.php: line 6: =: command not found 
/home/username/public_html/cron.php: line 8: syntax error near unexpected token `(' 
/home/username/public_html/cron.php: line 8: `$conn = new mysqli($server, $user, $pass, $dbname);' 

任何人都可以幫助解決這個問題嗎?謝謝。

+0

shell不知道如何解釋PHP代碼。使用php解釋器和/或shebang。 – mario

回答

0

您的腳本被解釋爲shell腳本。要在命令行運行PHP腳本:

php /home/username/public_html/cron.php 

或者將其添加到文件的頂部,並使其可執行:

#!/usr/bin/php 

(或路徑無論是你的PHP可執行文件)