Link to home
Create AccountLog in
Avatar of derrida
derrida

asked on

error on remote server:Parse error: syntax error, unexpected T_RETURN, expecting T_STRING or T_VARIABLE or '{' or '$'

hi
i have a method to create a database backup and it works great on my local machine.
once i try on remote server i get this error:
Parse error: syntax error, unexpected T_RETURN, expecting T_STRING or T_VARIABLE or '{' or '$'

and this is the method:
          
          public function createBackup($tables = '*' )
          {


                    //get all of the tables
                    if ( $tables == '*' )
                    {
                              $tables = array ( ) ;
                              $result = mysql_query ( 'SHOW TABLES' ) ;
                              while ( $row = mysql_fetch_row ( $result ) )
                              {
                                        $tables[ ] = $row[ 0 ] ;
                              }
                    }
                    else
                    {
                              $tables = is_array ( $tables ) ? $tables : explode ( ',' , $tables ) ;
                    }


                    //cycle through
                    foreach ( $tables as $table )
                    {
                              $result = mysql_query ("SET NAMES utf8");
                              $result = mysql_query ( 'SELECT * FROM ' . $table ) ;
                              $num_fields = mysql_num_fields ( $result ) ;


                              $this -> return.= "DROP TABLE IF EXISTS " . $table . ";" ;
                              $this -> return.= "\n\n";
                              $row2 = mysql_fetch_row ( mysql_query ( 'SHOW CREATE TABLE ' . $table ) ) ;
                              $this -> return.= "\n\n" . $row2[ 1 ] . ";\n\n" ;

                              for ( $i = 0 ; $i < $num_fields ; $i++ )
                              {
                                        while ( $row = mysql_fetch_row ( $result ) )
                                        {
                                                  $this -> return.= 'INSERT INTO ' . $table . ' VALUES(' ;
                                                  for ( $j = 0 ; $j < $num_fields ; $j++ )
                                                  {
                                                            $row[ $j ] = addslashes ( $row[ $j ] ) ;
                                                            $row[ $j ] = str_replace ( "\n" , "\\n" , $row[ $j ] ) ;
                                                            if ( isset ( $row[ $j ] ) )
                                                            {
                                                                      $this -> return.= '"' . $row[ $j ] . '"' ;
                                                            }
                                                            else
                                                            {
                                                                      $this -> return.= '""' ;
                                                            }
                                                            if ( $j < ($num_fields - 1) )
                                                            {
                                                                      $this -> return.= ',' ;
                                                            }
                                                  }
                                                  $this -> return.= ");\n" ;
                                        }
                              }
                              $this -> return.="\n\n\n" ;
                              
                    }
                    //$this -> return.="\n\n\n" ;

                    $this -> saveTheFile ( $this -> return ) ;
          }

Open in new window


the line number of the error point to this line:
   $this -> return.= "DROP TABLE IF EXISTS " . $table . ";" ;

Open in new window


again,all works on my local machine
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of derrida
derrida

ASKER

wow, yes it was the spaces around the ->, but i never had this issue. i had no idea this could be an issue.
thanks so much
Thanks for the points and thanks for using EE, ~Ray