Jump to content

Parse error: syntax error, unexpected ';'


anix

Recommended Posts

Hi all i am fairly new to using PHp and creating my own code however i am trying to install a script on my site and i get this message when i go to my home page to set everythink up "Parse error: syntax error, unexpected ';', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/sgcrys5/public_html/include/sql.inc.php on line 1" i have no idea were the error is in the code i have looked for a "," that is out of place and cannot spot 1 the full code is listed bellow, i hope someone can help me with this. thanks.

 

 

<?php
class sql
{
var $mysql_type = 1;
var$sql_server_type= 2;
var$db_type = 1; //mysql 
function sql( $db_type )
{
$this->db_type = $db_type;
}
function connection( $dm_name, $db_name, $db_username, $db_password, &$err )
{
if ( $this->db_type == $this->mysql_type )
{
$db = mysql_connect($dm_name, $db_username, $db_password );
if ( $db != FALSE )
{
if ( !@mysql_select_db($db_name,$db) )
{
$err = "select database error: " . mysql_error();
return FALSE;
}
}
else
{
$err = "mysql_connect error: " . mysql_error();
return FALSE;
}
}
else
{
$err = "not supported";
return FALSE;
}
return $db;
}
function sql_query($sql, $db, &$err)
{
if ( $this->db_type == $this->mysql_type )
{
$res = @mysql_query($sql, $db);
if ( !$res )
{
$err = mysql_error();
return FALSE;
}
return $res;
}
}
function sql_next_row(&$res )
{
if ( $this->db_type == $this->mysql_type )
{
return mysql_fetch_row($res);
}
}
function sql_num_row($res)
{
if ( $this->db_type == $this->mysql_type )
{
return @mysql_num_rows($res);
}
}
function sql_close($db)
{
if ( $this->db_type == $this->mysql_type )
{
@mysql_close($db);
}
}
function sql_free_result($res)
{
if ( $this->db_type == $this->mysql_type )
{
@mysql_free_result($res);
}
}
function sql_field_name($res,$index)
{
if ( $this->db_type == $this->mysql_type )
{
return @mysql_field_name($res,$index);
}
}
function sql_insert_id($res)
{
if ( $this->db_type == $this->mysql_type )
{
return mysql_insert_id($res);
}
}
}
?>

Link to comment
Share on other sites

Just tested the code you posted with PHP and no errors where reported. Your script could do with some indentation so the code becomes more readable

function my_func( --params-- )
{
    if( --condition-- )
    {
         // your code
    }
}

Rather than:

function my_func( --params-- )
{
if( --condition-- )
{
// your code
}
}

Link to comment
Share on other sites

i have also tested this code on my local server at home using windows and it runs fine but when i run it on my linux webserver i get these errors and dont know why, i asked the service provider to see if they knew but they just blame the code so im stuck, can any one help with this, i appreciate the fast replies so far thanks.

Link to comment
Share on other sites

thanks for all the help for the moment it seems that now i have indented the file correclty it has skipped that error and moved onto another one in another file so im presuming that for some reason it doesn't like the lack of indentation within each of the files so i will have to go through and indent them all as i go lol, this will no doubt take me some time but it needs to be done to ensure that everything runs ok, i just cant understand why on windows it runs without error!, thanks for all the help so far and i will keep you updated on my progress incase i need more assistance this forum is quite excellent thanks.

Link to comment
Share on other sites

Windows sucks. They're all about ignoring standards :-P

 

(Doubt the indentation alone was the issue though. Could be some garbage/unseen blank characters were in the files due to the way they were saved/transfered on your Windows box. Again, Windows blows gonads.)

Link to comment
Share on other sites

Umm. How have you come to that conclusion! PHP is cross platform independent. It could be any number of things which was causing the error.

 

Oh I'm sure the error was not an issue with the server OS...my opinion of PHP running on Windows is the same though. Especially with IIS.

Link to comment
Share on other sites

Could be how you set up your error reporting in php.ini. Here's your script:

 

<?php
class sql {
var $mysql_type = 1;
var$sql_server_type= 2;
var$db_type = 1; //mysql 
function sql( $db_type ) {
	$this->db_type = $db_type;
}

function connection( $dm_name, $db_name, $db_username, $db_password, &$err ) {
	if ( $this->db_type == $this->mysql_type ) {
		$db = mysql_connect($dm_name, $db_username, $db_password );
	}
	if ( $db != FALSE ) {
		if ( !@mysql_select_db($db_name,$db) )	{
			$err = "select database error: " . mysql_error();
			return FALSE;
		} else {
			$err = "mysql_connect error: " . mysql_error();
			return FALSE;
		}
	} else {
		$err = "not supported";
		return FALSE;
	}
	return $db;
} //function

function sql_query($sql, $db, &$err)	{
	if ( $this->db_type == $this->mysql_type ) {
		$res = @mysql_query($sql, $db);
		if ( !$res ) {
			$err = mysql_error();
			return FALSE;
		}
		return $res;
	}
}

function sql_next_row(&$res ) {
	if ( $this->db_type == $this->mysql_type ) {
		return mysql_fetch_row($res);
	}
}

function sql_num_row($res) {
	if ( $this->db_type == $this->mysql_type ) {
		return @mysql_num_rows($res);
	}
}

function sql_close($db) {
	if ( $this->db_type == $this->mysql_type ) {
		@mysql_close($db);
	}
}

function sql_free_result($res) {
	if ( $this->db_type == $this->mysql_type ) {
		@mysql_free_result($res);
	}
}

function sql_field_name($res,$index) {
	if ( $this->db_type == $this->mysql_type ) {
		return @mysql_field_name($res,$index);
	}
}

function sql_insert_id($res) {
	if ( $this->db_type == $this->mysql_type ) {
		return mysql_insert_id($res);
	}
}
} //class
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.