-2

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));
4

3 回答 3

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只是你的域名,你不需要$or {},所以你可以简单地写:

$handler = new PDO("mysql:host=myip.zapto.org;dbname={$gameserver}",$root,$mypassword);
于 2013-09-26T15:42:00.520 回答
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));
于 2013-09-26T15:43:47.443 回答
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);
于 2013-09-26T15:44:21.627 回答