0

我似乎无法找到为什么会出现意外的 T_variable 错误。我试图使用一个类来调用我的数据库。错误在第 18 行

 $query = $this->link->query("SELECT * FROM markers WHERE 1");  

这是我的整个班级。

有什么线索吗?

 class Users{
        private $link; 
        public function __construct(){
        $this->link = new Connection();
        $this->link = $this->link->dbConnect();
    }

   $query = $this->link->query("SELECT * FROM markers WHERE 1");  
   $query->$this->link->setFetchMode(PDO::FETCH_ASSOC);

    header("Content-type: text/xml");

      while($row = $stmt->fetch()) {  

            $node = $dom->createElement("marker");
            $newnode = $parnode->appendChild($node);
            $newnode->setAttribute("name", $row['name']);
            $newnode->setAttribute("adress", $row['adress']);
            $newnode->setAttribute("lat", $row['lat']);
            $newnode->setAttribute("lng", $row['lng']);
            $newnode->setAttribute("type", $row['type']);
      }
       echo $dom->saveXML();
}

第 18 和 19 行是

$query = $this->link->query("SELECT * FROM markers WHERE 1");  
$query->$this->link->setFetchMode(PDO::FETCH_ASSOC);
4

1 回答 1

3

你要么:

  • 在构造函数之后忘记关闭你的用户类
  • 忘记将您的代码包含在类方法中

前任:

class Users{
    private $link; 
    public function __construct(){
      $this->link = new Connection();
      $this->link = $this->link->dbConnect();
    }
}

或者:

class Users{
    private $link; 
    public function __construct(){
    $this->link = new Connection();
    $this->link = $this->link->dbConnect();
}

  public function someMethod() {
    $query = $this->link->query("SELECT * FROM markers WHERE 1");  
    $query->$this->link->setFetchMode(PDO::FETCH_ASSOC);

    header("Content-type: text/xml");

    while($row = $stmt->fetch()) {  

        $node = $dom->createElement("marker");
        $newnode = $parnode->appendChild($node);
        $newnode->setAttribute("name", $row['name']);
        $newnode->setAttribute("adress", $row['adress']);
        $newnode->setAttribute("lat", $row['lat']);
        $newnode->setAttribute("lng", $row['lng']);
        $newnode->setAttribute("type", $row['type']);
    }
    echo $dom->saveXML();
  }
}
于 2013-05-17T18:18:39.257 回答