davidp Posted April 2, 2007 Share Posted April 2, 2007 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 More sharing options...
utexas_pjm Posted April 2, 2007 Share Posted April 2, 2007 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 Link to comment https://forums.phpfreaks.com/topic/45212-receiving-a-syntax-error/#findComment-219513 Share on other sites More sharing options...
davidp Posted April 2, 2007 Author Share Posted April 2, 2007 ah thats true thanks. yeah the server is running 4.3.9. i am used to working on a server running 5.x. Thanks! Link to comment https://forums.phpfreaks.com/topic/45212-receiving-a-syntax-error/#findComment-219514 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.