Parse error: syntax error, unexpected '.', expecting
我收到此错误
Parse error: syntax error, unexpected '.', expecting '}' in /home/l2hantol/public_html/acp/core.php on line 37
第37行
function testServer($hostname,$user,$password,$database) {
try {
$handler = new PDO("mysql:host={$myip.zapto.org};dbname={$gameserver}",$root,$mypassword);
$handler = null;
return true;
} catch (PDOException $e) {
return false;
}
}
// Classes
class template {
public $template;
function load($filepath) {
$this->template = preg_replace("#\{(.*)\}#","<?php echo $1; ?>",file_get_contents($filepath));
答案 0 :(得分:1)
什么是$myip.zapto.org
?可能你想要这样的东西:
"mysql:host={$myip};dbname={$gameserver}"
或者如果你需要构建一个更复杂的字符串,可以在外面用以下内容完成:
$host = $myip . "zapto.org"
$handler = new PDO("mysql:host={$host};dbname={$gameserver}",$root,$mypassword);
修改强>
如果myip.zapto.org
只是您的域名,则不需要$
或{}
,因此您只需撰写:
$handler = new PDO("mysql:host=myip.zapto.org;dbname={$gameserver}",$root,$mypassword);
答案 1 :(得分:0)
这应该解决它:
function testServer($hostname,$user,$password,$database) {
try {
$handler = new PDO("mysql:host={$myip}.zapto.org;dbname={$gameserver}",$root,$mypassword);
$handler = null;
return true;
} catch (PDOException $e) {
return false;
}
}
// Classes
class template {
public $template;
function load($filepath) {
$this->template = preg_replace("#\{(.*)\}#","<?php echo $1; ?>",
file_get_contents($filepath));
答案 2 :(得分:0)
$handler = new PDO("mysql:host={$myip.zapto.org};dbname={$gameserver}"...
-^ ^-
您的连接查询中的此部分不视为字符串。
你可能想要:
$handler = new PDO("mysql:host={$myip}.zapto.org;dbname={$gameserver}" ...
尽管sprintf()
看起来更清晰:
$handler = new PDO(sprintf('mysql:host=%s.zapto.org;dbname=%s', $host, $dbname),
$myip, $gameserver);