Thread: Parse Error
View Single Post
Old 11-30-2006, 01:46 PM   #1 (permalink)
toe_cutter
Code Monkey
 
Join Date: Aug 2002
Location: Boston, MA
Posts: 79
toe_cutter is on a distinguished road
Send a message via ICQ to toe_cutter Send a message via AIM to toe_cutter Send a message via Yahoo to toe_cutter
Parse Error

This function worked when I had it on another machine, so I am not sure what it doesn't like. I can't remember which version of php it was, but I have 5.1.6 installed on a windows box. This happens when the class is included, and if I comment out the entire function Get it will work, btu I boviosuly cannot get anything. Any help is appreciated.

Thanks,
toe

Parse error: parse error, unexpected T_VARIABLE, expecting T_STRING in mysqlConnect.php on line 100

I highlighted line 100 in red.

Code:
class mysqlConnect {

	private $mycon;

/*****************************************************
	Constructor
*****************************************************/
	public function __construct( $DBHost, $DBUser, $DBPass, $DB ) {

		$this->mycon = @mysql_connect($DBHost, $DBUser, $DBPass)
			or exit('**ERROR** Could not connect to Database Host(' . $DBHost . ').');
		@mysql_select_db($DB, $this->mycon)
			or exit('**ERROR** Could not connect to Database (' .$DB . ').');
	}

	private function whereClause( $where, &$query ) {
		$query .= " where ";
		$moreThenOne = false;
		foreach (array_keys($where) as $key) {
			if($moreThenOne)
				$query .= " and ";
			$query .= $key . " = \"" . $where[$key] . "\" ";
			$moreThenOne=true;
		}
	}
/*****************************************************
	Generic sql Select that will return an array of the
	fields from a MySQL table.  The array keys will
	be the field names.

	$table - Is a table name
	$fields - Is an array of table fields you are retrieving.
	$where (optional)- Is an array that has a key value of the
			 database field you will search and the value
			 of that key is the value you will search for.
			 example: "ID"=>"3" would add where ID = "3"
			 to the query statement.
*****************************************************/
	public function Get( $table, $fields, $where=null ) {
		$query = "select * from " . $table . ";

		// If there is is a where clause in the SQL statement.
		if ($where) {
			$this->whereClause( $where, $query );
		}

		// Actually quering the database.
		$results = mysql_query($query, $this->mycon)
			or exit('**ERROR** Query ($query) failed.');
		$returnVal = array();

		// Walk through the results and match the field names with the
		// values in the field.
		while( $object = mysql_fetch_object($results) ) {
			$key = array();
			$value = array();
			for ( $i = 0; $i <= (sizeof($fields)-1); $i++ ) {
				array_push($key, $fields[$i]);
 				array_push($value, $object->$fields[$i]);
			}
			$returnVal[] = array_combine($key, $value);
		}
		return $returnVal;
	}

/*****************************************************
	Generic sql Insert that will return true or false.

	$table - Is a table name
	$fields - Is an array of table fields you are setting.
			  "key"=>"value". key is the field name and value
			  is what you will set it to.
	$where (optional)- Used for the update statement.
			 Is an array that has a key value of the
			 database field you will search and the value
			 of that key is the value you will search for.
			 example: "ID"=>"3" would add where ID = "3"
			 to the query statement.

	TODO:
	This function needs to handle the update statement
	as well. update agency set Name = '$name' where ID ='$id'
*****************************************************/
	public function Set( $table, $fields, $where=null ) {
		// insert into tableName (field1, field2) value ("value1", "value2);
		$query = "insert into " . $table ." (";

		$moreThenOne = false;
		foreach (array_keys($fields) as $key) {
			if($moreThenOne)
				$query .= ", ";
			$query .= $key;
			$moreThenOne=true;
		}
		$query .= ") values (";
		$moreThenOne = false;
		foreach (array_keys($fields) as $key) {
			if($moreThenOne)
				$query .= ", ";
			$query .= "\"" . $fields[$key] . "\"";
			$moreThenOne=true;
		}
		$query .= ")";

		// If there is is a where clause in the SQL statement.
		// Only used with the update statement.
		if ($where) {
			$this->whereClause( $where, $query );
		}

		// Actually quering the database.
		$results = mysql_query($query, $this->mycon)
			or exit('**ERROR** Query ($query) failed.');
		return(true);
	}

/*****************************************************
	Clean up the Database connection.
*****************************************************/
	public function close() {
		mysql_close($this->mycon);
	}

}
__________________
toe_cutter is offline   Reply With Quote