语法错误,意外'',期待'功能'

时间:2015-10-01 18:39:17

标签: php eclipse syntax

我使用Ecplise并且我得到了奇怪的语法错误,它表示在每个函数声明之前,每行都有四个错误(构造函数除外)。我真的不知道它来自哪里,我检查了每一行,我看不到" {}"或";"问题...

<?php
require_once('SqliteConnection.php');
class TrajetDAO {
private static $dao;

private function __construct() {
}​
public final static function getInstance() {
    if(!isset(self::$dao)) {
        self::$dao= new TrajetDAO();
    }
    return self::$dao;
}
​
public final function findAll() {
    $dbc = SqliteConnection::getInstance()->getConnection();
    $query = "select * from Trajet order by num";
    $stmt = $dbc->query($query);
    $results = $stmt->fetchALL(PDO::FETCH_CLASS, ’Trajet’);
    return $results;
}
​
public final function insert(DataObject $st){
    if($st instanceof Trajet){
        $dbc = SqliteConnection::getInstance()->getConnection();
        // prepare the SQL statement
        $query = "insert into Trajet(num, description, dateCrea) values (:n,:de,:da)";
        $stmt = $dbc->prepare($query);

        // bind the paramaters
        $stmt->bindValue(":n",$st->getNum(),PDO::PARAM_STR);
        $stmt->bindValue(":de",$st->getDescription(),PDO::PARAM_STR);
        $stmt->bindValue(":da",$st->getdateCrea(),PDO::PARAM_STR);
        // execute the prepared statement
        $stmt->execute($data);
    }
}

public function delete(DataObject $obj) {
    $dbc = SqliteConnection::getInstance()->getConnection();
    $query = $dbConnection->prepare('DELETE FROM Trajet WHERE num='.$Trajet->getNum().';');
    $query->execute();
}
​
public function update(DataObject $obj) {
    $dbc = SqliteConnection::getInstance()->getConnection();
    $query=$dbConnection->prepare('UPDATE Trajet SET num='.$Trajet->getNum().',description='.$Trajet->getDescription().',dateCrea='.$teacher->getDateCrea(). 'WHERE num='.$Trajet->getNum().';');
    $query->execute();
}
}
?>

1 个答案:

答案 0 :(得分:1)

我也像评论者一样认为,这是一个看不见的角色的问题。通过删除和替换语法错误附近的字符,我设法至少在PHPStorm中删除所有这些字符。

如果您自己编写此代码,则可能需要查看设置以找到根本原因。

<?php
require_once('SqliteConnection.php');
class TrajetDAO {
    private static $dao;

    private function __construct()
    {
    }

    public final static function getInstance()
    {
        if (!isset(self::$dao)) {
            self::$dao = new TrajetDAO();
        }

        return self::$dao;
    }

    public final function findAll()
    {
        $dbc = SqliteConnection::getInstance()->getConnection();
        $query = "select * from Trajet order by num";
        $stmt = $dbc->query($query);
        $results = $stmt->fetchALL(PDO::FETCH_CLASS, `Trajet`);

        return $results;
    }

    public final function insert(DataObject $st){
        if($st instanceof Trajet){
            $dbc = SqliteConnection::getInstance()->getConnection();
            // prepare the SQL statement
            $query = "insert into Trajet(num, description, dateCrea) values (:n,:de,:da)";
            $stmt = $dbc->prepare($query);

            // bind the paramaters
            $stmt->bindValue(":n",$st->getNum(),PDO::PARAM_STR);
            $stmt->bindValue(":de",$st->getDescription(),PDO::PARAM_STR);
            $stmt->bindValue(":da",$st->getdateCrea(),PDO::PARAM_STR);
            // execute the prepared statement
            $stmt->execute($data);
        }
    }

    public function delete(DataObject $obj) {
        $dbc = SqliteConnection::getInstance()->getConnection();
        $query = $dbConnection->prepare('DELETE FROM Trajet WHERE num='.$Trajet->getNum().';');
        $query->execute();
    }

    public function update(DataObject $obj) {
        $dbc = SqliteConnection::getInstance()->getConnection();
        $query=$dbConnection->prepare('UPDATE Trajet SET num='.$Trajet->getNum().',description='.$Trajet->getDescription().',dateCrea='.$teacher->getDateCrea(). 'WHERE num='.$Trajet->getNum().';');
        $query->execute();
    }
}