Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-11-02
2
Medium Priority
?
2,032 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
nahime earned 750 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

715 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