0

I'm using Ecplise and I'm getting strange syntax errors, it says there are four errors each located on the line before each function declaration (except for the constructor). I really don't know where it can come from, I checked every line and I see no "{}" or ";" problems...

<?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 Answers1

1

I also think, like the commenters, that this was an issue with an invisible character. By removing and replacing the characters near the syntax errors I managed to get rid of all of them in PHPStorm at least.

If you wrote this code yourself you might want to look into your setup to find the root cause.

<?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();
    }
}
Erik Johansson
  • 1,646
  • 1
  • 14
  • 19