webForumDet fria alternativet

Klass problem

0 svar · 217 visningar · startad av U2K

U2KMedlem sedan jan. 2000231 inlägg
#1

Det krånglar med min player klass..
problemet uppstår när man kör parent::Insert()

Varför?

// Index.php
include("mysql.php");
include("player_class.php");

$player = new Player;
$player->Add_player("$table","$player","$fodelse_id");
// Start of class player...
class Player extends MySQL {
  
  function Add_player($table,$player,$fodelse_datum) {
     
	 // Check to see if all inputs are correct
	 if($table == "" || $player == "" || $fodelse_datum == "")
	   echo "One or more arguments for function is missing.<br>";return false; exit;
	 
	 
	 // Connect..
	 parent::MySQL();
	 
	 // Set database
	 parent::Set_database("database","");
	 
	 // Insert value
	 parent::Insert("$table","'','$name','$fodelse_datum'");
	
  }

} // <-- End of class Player
// Start MySQL Class --> 

class MySQL{ 

var $host = "localhost"; 
var $username = "root"; 
var $password = ""; 
var $database = "";
var $dblink;
var $error;
   
   // Konstruktor 
   function MySQL(){  
	
         // Set values of each parameter 
		 $host = $this->host;
		 $username = $this->username;
		 $password = $this->password; 
		 $database = $this->database;
		 $error = $this->error;
		 
		 // Connect to MySQL If there were errors, give error msgs and exit 
         if(!$this->dblink = mysql_connect($host,$username,$password)){ 
            echo mysql_error(); return false; exit;} 
          
         // Retrun true if all is successfull 
         return true;} 
             
   // Function for inserting values into a table and cells 
   function Insert($table,$values){ // tablename,cols,values 
    
         // Check so that no arguments were empty 
         if($table == "" || $values == ""){ 
            echo "One or more argument(s) was empty for function '<b>Insert</b>' in the class '<b>MySQL</b>'"; return false; exit;} 
          
         // Do insert request, check for failure 
         if(!mysql_query("INSERT INTO $table VALUES($values)")){ 
            echo mysql_error(); return false; exit;} 
                
            // Return true if all is successfull 
   return true;} 
    
   function Update($table,$cols,$values,$where){ // tablename,columns,values,where 
       
         // Check so that no arguments were empty 
         if($table == "" || $cols == "" || $values == "" || $where == ""){ 
            echo "One or more argument(s) was empty for function '<b>Update</b>' in the class '<b>MySQL</b>'"; return false; exit;} 
             
         // Split values 
         $values = explode(",",$values); 
          
         // Split cells    
         $cols = explode(",",$cols); 

         // Check so that $values and $cells have the same amount of values 
         if(count($values) != count($cols)){ 
            echo "Array $colls ans array $values did not have the same amount of values in function '<b>Update</b>' in the class '<b>MySQL</b>'"; return false; exit;} 

         // Get the correct SET MySQL syntax 
         for($i=0;$i < count($values);$i++){ 
            $set .= $cols[$i] . "='" .$values[$i] . "'"; 
            if($i < count($values)-1){ 
               $set .= ",";}} 
            
         // Do update request 
         if(!mysql_query("UPDATE $table SET $set WHERE $where")){ 
            echo mysql_error(); return false; exit;} 
                    
            // Retrun true if all is succsessfull 
            return true;} 
             
   function Delete($table,$where){ // tablename,where
       
         // Check so that no arguments were empty 
         if($table == "" || $where == ""){ 
            echo "One or more argument(s) was empty for function '<b>Delete</b>' in the class '<b>MySQL</b>'"; return false; exit;} 
                   
         // Do Delete request 
         if(!mysql_query("DELETE FROM $table WHERE $where")){ 
            echo mysql_error(); return false; exit;} 
               
            // Retrun true if all is succsessfull 
            return true;} 
    
   function Select($table,$cols,$where="",$limit="",$orderby=""){ // table,columns,where,limit,orderby returns an array. 

         // Check so that no required arguments were empty 
         if($table == "" || $cols == ""){ 
            echo "One or more argument(s) was empty for function '<b>Select</b>' in the class '<b>MySQL</b>'"; return false; exit;} 
          
         // Check for WHERE statement    
         if($where != ""){ 
            $set .= " WHERE $where";} 
             
         // Check for ORDER BY statement 
         if($orderby != ""){ 
            $set .= " ORDER BY $orderby";} 
             
         // Check for LIMIT statement 
         if($limit != ""){ 
            $set .= " LIMIT $limit";} 
                         
         // Do Select request 
         $query = mysql_query("SELECT $cols FROM $table$set"); 
         while($sql_result = mysql_fetch_array($query,MYSQL_NUM)){ $array[] = $sql_result;} 
                
      // Return asociative array    
      return $array;} 
    
    function Showtables($show_thread) {
    
	  // Get values 
	  $link = $this->dblink;
	  $database = $this->database;
	  $error = $this->error;
	  
	  // Create result list
	  if (!$error)
        $result = mysql_list_tables($database);
	  else { 
	    return false;
		exit;
      }
		
    
	  // If not result.. explain why
      if (!$result) {
        print "Listing tables error " . "<br>";
        print 'MySQL Says: ' . mysql_error();
        exit;
       }      
	  
	  // print the talbles
      while ($row = mysql_fetch_row($result)) {
        print "Table: $row[0]\n" . "<br>";
		if (isset($show_thread)) {
	      $fields = mysql_list_fields($database, $row[0], $link);
		  $columns = mysql_num_fields($fields);
            echo "<ul>";
			for ($i = 0; $i < $columns; $i++) {
                echo "<li>" . mysql_field_name($fields, $i) . " [" . $this->fieldinfo(mysql_field_name($fields, $i),$row[0]) . "] " . "<br></li>";
            }
			echo "</ul>";
		}
      }
	
      // Free result
        mysql_free_result($result);	  
			
	} // <-- End of function
	
	function Set_database($db,$show_succes="yes") {
	
	  // Check so required argument are not empty
	  if($db==""){ 
          echo "One or more argument(s) was empty for function '<b>Set_database</b>' in the class '<b>MySQL</b>'"; return false; exit;} 	
	  
	  $dblink = $this->dblink;
	    
	  // Create a list with databases
	  $db_list = mysql_list_dbs($dblink);
	  
	  // Chech to see if database exists
	  $i = 0;
      $count = mysql_num_rows($db_list);
      while ($i < $count && $flag==0) {
        
		if (mysql_db_name($db_list, $i) == $db) 
		  $flag=1;
		else
		  $flag=0;
		  
        $i++;
      }

	 
      // If flag=0 then database do not exist
	  if ($flag==0){
	   echo "The database you wanted to use don't exist"; 
	   $this->error = true;
	   return false; 
	   exit;
	   }	  
	   
	  // If succesfull
	  if($flag==1 && $show_succes=="yes")
	  {
	  $this->database = $db;
	  mysql_select_db($db) or die(mysql_error());
	  echo "Using Database <b>[". $db . "]</b>";
	  }
	  
	
	return true;} // <-- End of function
	
	function fieldinfo($field,$table) {
	 
	 // Check if field is not empty
	 if($field=="" && $table=="") {
	   echo "One or more arguments in function '<b>fieldinfo()</b>' is empty"; return false; exit; }
	 
	 $result = mysql_query("select $field from $table");
     
	 $i = 0;

	 while ($i < mysql_num_fields($result)) {
           $meta = mysql_fetch_field($result);
           if (!$meta) {
             echo "No info";
           }
     
	 // Echo out the parameters...
	 
	 if($meta->type)
	   $str = $meta->type;
	   
	 if($meta->primary_key)
	   $str = $str . ", primary key";
	   
	 $i++;
	 }
	 
	 mysql_free_result($result);

	 
	 return $str;
	 
	} // <-- End of function  
	
   // <-- End Class 
}
Genererad på 376 ms · cache AV · v20260730165559-full.f96bc7eb