Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
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
Old 11-30-2006, 02:45 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,139
Belisarius is on a distinguished road
It's the first line of the function:
Code:
$query = "select * from " . $table . ";
Unclosed quote.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 12-01-2006, 06:06 AM   #3 (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
Thank you very much. Sometimes all it takes is another set of eyes.

-toe
__________________
toe_cutter is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
parse error problem in game.. can't seem to find problem solution. slashdot Standard C, C++ 5 08-03-2005 08:15 PM
Parse Error with "else" in simple game. slashdot Standard C, C++ 7 07-20-2005 08:13 AM
Parse Error Ilya020 PHP 2 11-17-2003 05:27 PM


All times are GMT -8. The time now is 12:15 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting