1
我在PHP文件的開頭這段代碼:爲什麼此PHP代碼在一臺機器上運行並在另一臺機器上運行失敗?
<?php
$url = 'https://api.stackexchange.com/2.1/info';
$data = array("site" => 'space', "key" => "T1h2I3s4I5s6M7y8A9p0I1k2E3y!");
$response = (new Curl)->exec($url . '?' . http_build_query($data), [CURLOPT_ENCODING => 'gzip']);
// ^^ Line 6 ^^
$obj = json_decode($response);
$timestamp = date("Y:m:d H:i:s");
$dbhost = "localhost";
$dbname = "statengine";
$dbuser = "statengine";
$dbpass = "#P1aSs3WoR5d!";
mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
當我將遠程Ubuntu 12.04服務器上運行它,它運行良好。但是,當我在本地服務器上運行(Ubuntu的12.04再次)時,出現此錯誤:
$ php getstats.php
PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /home/<me!>/Desktop/statengine/getstats.php on line 6
我確信,捲曲安裝在機器上。我可以提供任何額外的信息,只需要問!
如何讓它工作?
果然 - 我的本地機器上有5.3.10。謝謝! – Undo