Autor Zpráva
rad
Profil *
mam problem s timto kodem co je spatne ?

  public function query($query, $return='true')
    
     {
     
        $this->lastquery = $query;

        $this->count++;
        
      if ($this->lastquery===FALSE)
      
      {     
      header('Location: http://www.google.com/');
      echo 'Error with Query('.$query.'): '.mysql_error();
      } 
        
     else    
     {     
     $this->result = mysql_query($query, $this->connect);    
     }
     
     }
rad
Profil *
zkousim si vytvorit class pro pripojeni k databazi a pro zobrazeni vysledku


vypada to takto problem je ze ta podminka co jsem psal predtim nejak nefunguje
<?php      

class database {   


    private $datebase;
    private $server;
    private $username;
    private $password;              
    private $result;
    public $connect;
    public $lastquery;
    public $count=0;
    private $select;  
      
    public function __construct($database='portfolio', $server='localhost', $username='root', $password='')
    {
    $this->connect = mysql_connect($server, $username, $password); 
    //or die ('Error: '.mysql_error());  //DIE
    if ($this->connect===FALSE)       
    {
    
    header('Location: http://www.google.com/');
    
    echo mysql_error();    
   
    }    
    else 
    {    
    $this->select=mysql_select_db($database, $this->connect);          
    
    if ($this->select===FALSE)    
    
    {
            
    header('Location: http://www.google.com/');
        
    echo mysql_error();   // mail !!!   
        
    }   
                   
    else
    {   
    mysql_query("SET CHARACTER SET utf8"); //utf8
    
    mysql_query("SET NAMES utf8 "); 		   //utf8  
    }
    } 
    }   
         
    public function disconnect()
    {
    mysql_close($this->connect);
    }


    public function query($query, $return='true')  
    {     
    $this->lastquery = $query;
    $this->count++;
        
    if ($this->lastquery===FALSE)      
      {     
      header('Location: http://www.google.com/');      
      echo 'Error with Query('.$query.'): '.mysql_error();
      }         
      else    
      {     
      $this->result = mysql_query($query, $this->connect);    
      }     
    }   
            
                 
    public function num_rows()    
    {  
        return @mysql_num_rows($this->result);  
    }

    public function fetch_array(&$result){

        return @mysql_fetch_array($this->result);

    }

    public function fetch_assoc()
    {

        return @mysql_fetch_assoc($this->result);
        
    
    }
    
    public function insert_id(){

        return @mysql_insert_id();

    }

    public function escape($string)
    {
    if(!get_magic_quotes_gpc()) {                 //if cest ok faire rien si non faire mysql_real_escape_string function
    return mysql_real_escape_string($string);
    }
    else {
	  return $string;    
    }
    }
    
    public function strip (&$string)    
    {
    return stripslashes($string);
    
    }

    public function result($query, $column, $id=0){

    return mysql_result($query, $id, $column);

    }        
  public function __destruct()
  {
  
  }
    
}
?>   
Taps
Profil
rad:
nemá být v podmínce jen == ?
rad
Profil *
ne
rad
Profil *
protoze == FALSE muze byt taky 0 a to neni to same jako FALSE === kontroluje i typ
Taps
Profil
rad:
protoze == FALSE muze byt taky 0 a to neni to same jako FALSE === kontroluje i typ
to vím
jsim
Profil
WTF? co to je za třídu proboha? Pěkná prasečina ...

ale aby nebyl OT, k tý tvý funkci ...
1) proč tam je $return = 'true' ?? Co to má znamenat?
2) Podmínka funguje správně ... jak čekáš, že se bude vyhodnocovat, když porovnáváš i typ proměnné v podmínce? proměnná by musela být nastavena na FALSE, aby výraz skočil do první větve ... všechny ostatní případy skočí do větve else ...
rad
Profil *
jsim:
a jak by to teda melo vypadat ?
Co je tam prasecina ?
rad
Profil *
  public function query($query) 
     
    {
         
    $this->lastquery = $query;
    $this->count++;             
    $this->result = mysql_query($query, $this->connect); 
    if ($this->result===FALSE)
    {echo 'Error with Query('.$query.'): '.mysql_error();}               
    }   


tohle funguje normalne a proc tri ? http://fr2.php.net/manual/en/function.mysql-query.php
Tori
Profil
rad:
Porovnávání typu tady asi opravdu není potřeba (když funkce vrací buď popisovač výsledku, nebo boolean). Rozdíl byl přeci v tom, že před tím jste neporovnával výsledek vrácený databází, ale dotaz. Takže první větev by se provedla jedině při volání database->query(false);

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0