Jump to content

unexpected (T_VAR), expecting variable (T_VARIABLE)


cybernet

Recommended Posts

so i found a pdo class to connect to mysql with pdo and looks easy to customize

 

however i have an error that i can't figure it out

 

class

<?php

class ApplicationResourcePool 
{
    static var $_dbHandle;   // line 5

    private static $_dbConfig = array(
        'dsn'      => 'mysql:dbname=vax',
        'username' => 'vax',
        'password' => 'veryrandpasswd',

    );
    public static getDbHandle(){
        if(self::$_dbHandle == null){
            self::$_dbHandle = new PDO(
                self::$_dbConfig['dsn'] , 
                self::$_dbConfig['username'], 
                self::$_dbConfig['password'] 
            );
        }
        return self::$_dbHandle;
    }

}

class StockMapper
{
    protected $_dbh; 
    public __construct($dbh = null)
    {
        if($dbh == null){
            $this->_dbh = ApplicationResourcePool::getDbHandle();
        } else {
            $this->_dbh = $dbh;
        }

    }
    public getStockById($stockId){

        $sth=$this->_dbh->prepare("SELECT * from stock WHERE id = :stockId"); 
        $sth->bindParam(":stockId", $stockId);
        $sth->execute();
        $result = $sth->fetch(PDO::FETCH_ASSOC);
        return $result[0];
    }
}

$stockMapper = new StockMapper();
$stockData = $stockMapper->getStockById('302');

?>
Parse error: syntax error, unexpected 'var' (T_VAR), expecting variable (T_VARIABLE) in /path/index.php on line 5

i really don't know what to do :sweat:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.