How to fix this error?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to fix this error?

    Looking through all my old scripts i purchased i came across the makolinks script (it a get paid to type script like paid to click).

    Thought i would install this on my test server (not used this script in years)

    I get this error:

    Fatal error: Cannot redeclare DB_Sql::free_result() in /home/xxxxxx/domains/xxxxxxx/public_html/includes/mysql.php on line 35

    This is the code on line 35:

    Code:
    Code:
    function free_result($sql) {
    $this->free_result($sql);
    }
    I know this is a old script and may not function on the latest version of mysql but any ideas how to fix this?

    #2
    Originally posted by theboss View Post
    Code:
    Code:
    function free_result($sql) {
    $this->free_result($sql);
    }
    I only use recursion in Java i never used it in php but looking at your code it's not making sense to recurse a method that does nothing, it may be helpful to comment out that method and see if you get any errors
    libra.wen.ru

    Comment


      #3
      This is the full code of the page if its more helpful?

      PHP Code:
      <?
      class DB_Sql {
        var $Host     = "localhost"; // Hostname of our MySQL server.
        var $Database = "xxxx"; // Logical database name on that server.
        var $User     = "xxxxx"; // User und Password for login.
        var $Password = "xxxxxx";

        var $Link_ID  = 0;  // Result of mysql_connect().
        var $Query_ID = 0;  // Result of most recent mysql_query().
        var $Record   = array();  // current mysql_fetch_array()-result.
        var $Row;           // current row number.

        var $Errno    = 0;  // error state of query...
        var $Error    = "";
        var $num_queries = 0;


         function halt($msg) {
          printf("</td></tr></table><b>Database error:</b> %s<br>\n", $msg);
          printf("<b>MySQL Error</b>: %s (%s)<br>\n",
            $this->Errno,
            $this->Error);
          die("Session halted.");
        }
        
       function free_result($query_id=-1) {
          // retrieve row
          if ($query_id!=-1) {
            $this->query_id=$query_id;
          }
          //return @mysql_free_result($this->query_id);
        }
        
        
      function free_result($sql) {
      $this->free_result($sql);
      }


        function connect() {
          if ( 0 == $this->Link_ID ) {
            $this->Link_ID=mysql_connect($this->Host, $this->User, $this->Password);
            if (!$this->Link_ID) {
              $this->halt("Link-ID == false, connect failed");
            }
            if (!mysql_query(sprintf("use %s",$this->Database),$this->Link_ID)) {
              $this->halt("cannot use database ".$this->Database);
            }
          }
        }

         function free_result($query_id=-1) {
          if ($query_id!=-1) {
            $this->query_id=$query_id;
          }
        }

        
        function fetch_array($query_id=-1,$query_string="") {
          if ($query_id!=-1) {
            $this->query_id=$query_id;
          }
          if ( isset($this->query_id) ) {
            $this->record = mysql_fetch_array($this->query_id);
          } else {
            if ( !empty($query_string) ) {
              $this->halt("Invalid query id (".$this->query_id.") on this query: $query_string");
            } else {
              $this->halt("Invalid query id ".$this->query_id." specified");
            }
          }
          return $this->record;
      }


          function query($Query_String) {
      //  $this->connect();
          $this->num_queries++;
          #printf("<br><font color=red><b>Debug: query = %s</b></font><br>", $Query_String); // Use for debugging
          $this->Query_ID = mysql_query($Query_String,$this->Link_ID);
          $this->Row   = 0;
          $this->Errno = mysql_errno();
          $this->Error = mysql_error();
          if (!$this->Query_ID) {
            $this->halt("Invalid SQL: ".$Query_String);
          }
          return $this->Query_ID;
        }


        function next_record() {
          $this->Record = mysql_fetch_array($this->Query_ID);
          $this->Row   += 1;
          $this->Errno = mysql_errno();
          $this->Error = mysql_error();
          $stat = is_array($this->Record);
          if (!$stat) {
            mysql_free_result($this->Query_ID);
            $this->Query_ID = 0;
          }
          return $stat;
        }


        function seek($pos) {
          $status = mysql_data_seek($this->Query_ID, $pos);
          if ($status)
            $this->Row = $pos;
          return;
        }


        function num_rows() {
          return mysql_num_rows($this->Query_ID);
        }

        function num_fields() {
          return mysql_num_fields($this->Query_ID);
        }

        
        function f($Name) {
          return $this->Record[$Name];
        }

        function p($Name) {
          print $this->Record[$Name];
        }

        function affected_rows() {
          return @mysql_affected_rows($this->Link_ID);
        }

        
        
          function get_temps() {
              while ($row = mysql_fetch_array($this->Query_ID)) {
                  $templ[$row["id"]] = $row['con'];
                  }
                  echo "$templ[1]<br>$templ[2]";
          }

          function get_temp() {
      return mysql_fetch_array($this->Query_ID);
          }

        function query_first($query_string) {
          // does a query and returns first row
          $query_id = $this->query($query_string);
          $returnarray=$this->fetch_array($query_id, $query_string);
          $this->free_result($query_id);
          return $returnarray;
        }


          function sql_close()
              {
                  if($this->db_connect_id)
                  {
                      if($this->query_result)
                      {
                          @mysql_free_result($this->query_result);
                      }
                      $result = @mysql_close($this->db_connect_id);
                      return $result;
                  }
                  else
                  {
                      return false;
                  }
          }


        
      }





        
      ?>
      Last edited by arnage; 27.06.12, 18:55.

      Comment


        #4
        Remove
        PHP Code:
        function free_result($sql) {
        $this->free_result($sql);

        libra.wen.ru

        Comment


          #5
          Originally posted by theboss View Post
          Looking through all my old scripts i purchased i came across the makolinks script (it a get paid to type script like paid to click).

          Thought i would install this on my test server (not used this script in years)

          I get this error:

          Fatal error: Cannot redeclare DB_Sql::free_result() in /home/xxxxxx/domains/xxxxxxx/public_html/includes/mysql.php on line 35

          This is the code on line 35:

          Code:
          Code:
          function free_result($sql) {
          $this->free_result($sql);
          }
          I know this is a old script and may not function on the latest version of mysql but any ideas how to fix this?

          Replace With This One:
          Code:
          if (!function_exists('free_result')) {
          function free_result($sql) {
          $this->free_result($sql);
          }
          }
          May be this solve your problem!

          Comment


            #6
            Originally posted by theboss View Post

            Fatal error: Cannot redeclare DB_Sql::free_result() in /home/xxxxxx/domains/xxxxxxx/public_html/includes/mysql.php on line 35
            Seems like a double include, the page where DB_SQL class is located was included already, try require_once

            Comment

            Working...
            X