Jump to content

receiving a syntax error


davidp

Recommended Posts

I am receiving what looks to be like a relatively simple syntax error, but I am at a loss for exactly WHY I am receiving it, because the syntax looks correct to me. 

 

Here is my code.  It is fairly short:

 

<?

/********************************
dbm.php

Author: David Pruitt

Purpose: This file handles
connections to the database
for the music store.
********************************/

class DBM
{
    private $connected;
    
    function __construct ( )
    {
$server = "Edited out for security";
$db = "Edited out for security";
$username = "Edited out for security";
$password = "Edited out for security";

$this->connected = false;

if (mysql_connect($server, $username, $password)) 
{
    if (mysql_select_db($db)) 
    {
	$this->connected=true;
    }
}
    }
    
    function isConnected ( )
    {
return $this->connected;
    }
}

global $dbm;
$dbm = new DBM();

// Check if the database is available.
if (!$dbm->isConnected()) {
print 'Unable to access the Speeches database at this time.<p>Sorry for the inconvenience.';
exit;
}
else print 'Connected!';

?>

 

The error that I am receiving is the following:

 

Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /users/home2/ugrad/d/dpru/public_html/db/dbm.php on line 15

 

It appears to be on the line where i declare

 

private $connected;

 

Why would it complain about that?  Anyone see anything wrong with that code?

Link to comment
https://forums.phpfreaks.com/topic/45212-receiving-a-syntax-error/
Share on other sites

My guess would be that you're running PHP4.x.  The private keyword is undefined in < PHP 5.x.  Use var instead.  Furthermore there is no __construct() in PHP4 so you'll want to cahnge your code to look like this:

 

<?php

/********************************
dbm.php

Author: David Pruitt

Purpose: This file handles
connections to the database
for the music store.
********************************/

class DBM
{
    var $connected;
    
    function DBM( )
    {
$server = "Edited out for security";
$db = "Edited out for security";
$username = "Edited out for security";
$password = "Edited out for security";

$this->connected = false;

if (mysql_connect($server, $username, $password)) 
{
    if (mysql_select_db($db)) 
    {
	$this->connected=true;
    }
}
    }
    
    function isConnected ( )
    {
return $this->connected;
    }
}

global $dbm;
$dbm = new DBM();

// Check if the database is available.
if (!$dbm->isConnected()) {
print 'Unable to access the Speeches database at this time.<p>Sorry for the inconvenience.';
exit;
}
else print 'Connected!';

?>

 

Best,

 

Patrtick

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.