Solved

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

Posted on 2008-11-02
2
2,015 Views
Last Modified: 2013-12-13
What am I doing wrong?

I am making a class for connecting to a MySql database, but when testing it, it brings back a blank page. Debugging in eclipse reveals Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in c:\program files\easyphp1-8\www\lib\framework\system.data.mysqlclient.php on line 27

/**
 * Defines a connection to the database
 *
 */
class MySqlConnection
{
	var $Connection = 0;
	var $server;
	var $username;
	var $password;
	var $database;
	/**
	 * Initializes connection to a MySQL Server
	 *
	 * @param string $Server
	 * @param string $Username
	 * @param string $Password
	 * @param string $Database
	 */
	function __construct($Server, $Username, $Password, $Database)
	{
		$res = mysql_connect($Server, $Username, $Password);
		if(!$res) throw new Exception(MySqlConnectionException);
		if(!mysql_select_db($Database, $res)) throw new Exception(MySqlDatabaseOperationException);
		$Connection = $res;
	}
	/**
	 * Returns last occured error
	 *
	 * @return string
	 */
	function GetLastError()
	{
		return mysql_error();
	}
	
	/**
	 * Closes the database connection
	 *
	 */
	function Close()
	{
		mysql_close($Connection);
	}
}

Open in new window

0
Comment
Question by:webfullcircle
2 Comments
 
LVL 8

Accepted Solution

by:
nahime earned 250 total points
ID: 22862077
On my test machine your code works (adding <?php at the start and ?> at the end).
I've tried to instantiate the class as in the code snippet
<?php
/**
 * Defines a connection to the database
 *
 */
class MySqlConnection
{
        var $Connection = 0;
        var $server;
        var $username;
        var $password;
        var $database;
        /**
         * Initializes connection to a MySQL Server
         *
         * @param string $Server
         * @param string $Username
         * @param string $Password
         * @param string $Database
         */
        function __construct($Server, $Username, $Password, $Database)
        {
                $res = mysql_connect($Server, $Username, $Password);
                if(!$res) throw new Exception(MySqlConnectionException);
                if(!mysql_select_db($Database, $res)) throw new Exception(MySqlDatabaseOperationException);
                $Connection = $res;
        }
        /**
         * Returns last occured error
         *
         * @return string
         */
        function GetLastError()
        {
                return mysql_error();
        }
        
        /**
         * Closes the database connection
         *
         */
        function Close()
        {
                mysql_close($Connection);
        }
}
 
$myvar = new MySqlConnection("127.0.0.1", "username", "password", "DATABASE");
?>

Open in new window

0
 
LVL 1

Author Comment

by:webfullcircle
ID: 22862106
That's odd.. I was using the require_once call and it did not work, but worked with include
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question