Forum Moderators: coopster

Message Too Old, No Replies

Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION'

         

mdaislam

3:22 pm on Jun 22, 2005 (gmt 0)

10+ Year Member



hi, i am new php. i was following a book to learn php and running the code from the book. i found one problem with parse error. can anyone tell me why is this problem? the problem is :

Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in C:\tshirtshop\include\database.php on line 7

the code is :

<?php
// reference the PEAR DB library
require_once 'DB.php';
// class providing generic data access functionality
class DbManager
{
$db;

// open database connection in the constructor
function __construct($connectionString)
{
$this->db = DB::connect($connectionString,
USE_PERSISTENT_CONNECTIONS);
if (DB::isError($this->db))
trigger_error($this->db->getMessage(), E_USER_ERROR);
$this->db->setFetchMode(DB_FETCHMODE_ASSOC);
}
// close the connection
public function DbDisconnect()
{
$this->db->disconnect();
}
// wrapper class for PEAR DB's query() method
public function DbQuery($queryString)
{
$result = $this->db->query($queryString);
if (DB::isError($result))
trigger_error($result->getMessage(), E_USER_ERROR);
return $result;
}
// wrapper class for PEAR DB's getAll() method
public function DbGetAll($queryString)
{
$result = $this->db->getAll($queryString);
if (DB::isError($result))
trigger_error($result->getMessage(), E_USER_ERROR);
return $result;
}
// wrapper class for PEAR DB's getRow() method
public function DbGetRow($queryString)
{
$result = $this->db->getRow($queryString);
if (DB::isError($result))
trigger_error($result->getMessage(), E_USER_ERROR);
return $result;
}
// wrapper class for PEAR DB's getOne() method
public function DbGetOne($queryString)
{
$result = $this->db->getOne($queryString);
if (DB::isError($result))
trigger_error($result->getMessage(), E_USER_ERROR);
return $result;
}



}
?>

Sathallrin

3:55 pm on Jun 22, 2005 (gmt 0)

10+ Year Member



It is getting to this part:
$db;
and not knowing what to do with it. You need to change it to
var $db;
for it to be recognized as a variable specific to the class.

mdaislam

5:27 pm on Jun 22, 2005 (gmt 0)

10+ Year Member



thanks for responding. i need to declare this variable as public. so i wrote

public $db;

but still its showing the same error

Sathallrin

5:36 pm on Jun 22, 2005 (gmt 0)

10+ Year Member



Are you running this on a server with PHP 5?

Timotheos

5:39 pm on Jun 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe you want global $db? Public is for functions.

Sathallrin

5:58 pm on Jun 22, 2005 (gmt 0)

10+ Year Member



Public variables are perfectly valid in PHP 5. They can be accessed like this:
$myclass = new ClassName();
$myclass->VariableName;

global variables are only accessed by the variable name.

jatar_k

6:41 pm on Jun 22, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



take a look at those errors here and see if this gives you more info

PHP List of Parser Tokens [php.net]

mdaislam

3:39 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



hi Sathallrin, i am using php 4.3. and the book is written on php 5. so can anybody tell me what it should be in php 4.3.

i need help

electricocean

7:17 pm on Jun 23, 2005 (gmt 0)

10+ Year Member



use var $db. that's for php 4.x

i found this helpful: [zend.com...]

electricocean