global loswerden

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • #16
    ib/user/userhandler.class.php
    PHP-Code:
    class UserHandler 
    {
    //restliche funktionen entfernt
    public function getnamebyid($id)
    {
        
    $username $db->MysqlDB-......................... 
    was ist $db?
    das ist in funktion nirgendwo definiert!
    hast du vielleicht
    Registry::getInstance()->MysqlDB gemeint?
    Slava
    bituniverse.com

    Kommentar


    • #17
      ja das is ja meine frage jetzt^^ muss ich in der function [COLOR=#000000][COLOR=#006600]();
      [/COLOR][COLOR=#0000cc]$db [/COLOR][COLOR=#006600]= [/COLOR][COLOR=#0000cc]Registry[/COLOR][COLOR=#006600]::[/COLOR][COLOR=#0000cc]getInstance[/COLOR][COLOR=#006600](); [/COLOR][/COLOR]reinsetzen ?

      edit:

      ah habs

      PHP-Code:
      $username Registry::getInstance()->MysqlDB->querySingleItem("SELECT username FROM user WHERE uid =$id"__FILE____LINE__); 
      Zuletzt geändert von coty; 17.07.2009, 18:34.

      Kommentar


      • #18
        tja,
        du kannst natürlich auch eine objectvariable bei instanzieren belegen
        Code:
        class ...
         private db='false';
        ....
        public function __construct(){
          $this->db=Registry::getInstance()->MysqlDB;
        }
        dann kannst du in den methoden $this->db->querySingleItem(.. nutzen
        mir mach mehr sorgen, dass deine code nicht optimal ist.
        PHP-Code:
        $username $db->MysqlDB->querySingleItem("SELECT username FROM user WHERE uid =$id"__FILE____LINE__);

          if (
        $db->MysqlDB->querySingleItem("SELECT status FROM user WHERE uid =$id"__FILE____LINE__) != 'activ') { 
        ist doch nicht besonders gut. Du kannst doch schon bei erster Abfrage username und status in einem query abfragen.

        auch bei index.php kannst du 2-te query vermeiden

        nicht getestet:
        Code:
        SELECT n1.* ,(SELECT COUNT(newsid) FROM newscomments where newsid=n1.id) as comentar_anzahl
                FROM news  ORDER BY added DESC LIMIT 10
        oder?
        Zuletzt geändert von Slava; 18.07.2009, 09:56.
        Slava
        bituniverse.com

        Kommentar


        • #19
          jupp beim ersten qry hab ich durch nen fetch_object ersetzt und $row->username und $row->status genommen und das 2te qry mit nem join ^^

          da hats noch sehr viel zu optimieren erstmal bastel ich mir nur die funktionen zusammen das optimieren nehme ich mir später vor =)


          wie gesagt bin noch anfänger^^ muss mich da langsam rantasten



          danke für eure hilfe

          Kommentar


          • #20
            seit neustem bekomme ich ne notice:

            Notice: Undefined property: Registry::$MysqlDB in /home/mpl/workspace/PIP/lib/Registry.php on line 23


            PHP-Code:
                public final function __get($was)
                {
            /*line 23*/   return self::$registry->$was;




            bootstrap.php

            PHP-Code:
            $workpath $_SERVER["DOCUMENT_ROOT"];
            require_once(
            "$workpath/lib/Registry.php");
            require_once(
            "$workpath/lib/database/mysqldb.class.php");

            $db     Registry::getInstance();
            $db->MysqlDB       = new MysqlDB(); 
            </b>

            mysqldb.class.php
            PHP-Code:
            <?php
             
            class MysqlDB {
              protected 
            $mysqli;
              protected 
            $showerror true;   // set FALSE if you don't want to see error messages
              
            protected $showsql   true;  // set TRUE if you want to see all SQL queries for debugging purposes
              
            protected $host;
              protected 
            $user;
              protected 
            $password;
              protected 
            $database;
              protected 
            $sqlcounter 0;     // counter for SQL commands
              
            protected $rowcounter 0;     // counter for returned SELECT rows
              
            protected $dbtime     0;     // counter for time needed to execute queries
              
            protected $starttime;
              protected 
            $showsqls;
             
             
              
            // constructor
              
            function __construct() {
                  
            $workpath $_SERVER["DOCUMENT_ROOT"];
                  require_once(
            "$workpath/lib/secrets.php");
                  
            $this->host         $host;
                  
            $this->user         $user;
                  
            $this->password     $password;
                  
            $this->database     $database;
                
            $this->mysqli = @new mysqli($this->host$this->user$this->password$this->database);
                if(
            mysqli_connect_errno()) {
                  
            $this->printerror("Sorry, no connection! (" mysqli_connect_error() . ")");
                  
            $this->mysqli FALSE;
                  exit();
                }
             
                
            $this->showsqls['seconds'] = array();
                
            $this->showsqls['query'] = array();
                
            $this->showsqls['file'] = array();
                
            $this->showsqls['line'] = array();
             
             
                
            $this->starttime $this->microtime_float();
              }
             
              
            // destructor
              
            function __destruct() {
                
            $this->close();
               }
             
              
            // explicit close
              
            function close() {
                if(
            $this->mysqli)
                  
            $this->mysqli->close();
                  
            $this->mysqli FALSE;
              }
             
              function 
            getMysqli() {
                return 
            $this->mysqli; }
                
              
            // execute SELECT query, return array
              
            function queryObjectArray($sql$file 'not'$line 'set') {
                
            $this->sqlcounter++;
                
            $time1  $this->microtime_float();
                
            $result $this->mysqli->query($sql);
                
            $time2  $this->microtime_float();
                
            $ttime  = ($time2 $time1);
                
            $this->printsql($sql,$ttime$file$line);
                
            //$this->dbtime += ($time2 - $time1);
                
            $this->dbtime += $ttime;
                if(
            $result) {
                  if(
            $result->num_rows) {
                    while(
            $row $result->fetch_object())
                      
            $result_array[] = $row;
                    
            $this->rowcounter += sizeof($result_array);
                    return 
            $result_array; }
                  else
                    return 
            FALSE;
                } else {
                  
            $this->printerror($this->mysqli->error);
                  return 
            FALSE;
                }
              }
             
              
            // execute SELECT query, return array
              
            function queryArray($sql$file 'not'$line 'set') {
                
            $this->sqlcounter++;
                
            $time1  $this->microtime_float();
                
            $result $this->mysqli->query($sql);
                
            $time2  $this->microtime_float();
                
            $ttime  = ($time2 $time1);
                
            $this->printsql($sql,$ttime$file$line);
                
            //$this->dbtime += ($time2 - $time1);
                
            $this->dbtime += $ttime;
                if(
            $result) {
                  if(
            $result->num_rows) {
                    while(
            $row $result->fetch_array())
                      
            $result_array[] = $row;
                    
            $this->rowcounter += sizeof($result_array);
                    return 
            $result_array; }
                  else
                    return 
            FALSE;
                } else {
                  
            $this->printerror($this->mysqli->error);
                  return 
            FALSE;
                }
              }
             
             
              
            // execute a SELECT query which returns only a single
              // item (i.e. SELECT COUNT(*) FROM table); return
              // this item
              // beware: this method return -1 for errors (not 0)!
              
            function querySingleItem($sql$file 'not'$line 'set') {
                
            $this->sqlcounter++;
                
            $time1  $this->microtime_float();
                
            $result $this->mysqli->query($sql);
                
            $time2  $this->microtime_float();
                
            $ttime  = ($time2 $time1);
                
            $this->printsql($sql,$ttime$file$line);
                
            //$this->dbtime += ($time2 - $time1);
                
            $this->dbtime += $ttime;
                if(
            $result) {
                  if (
            $row=$result->fetch_array()) {
                    
            $result->close();
                    
            $this->rowcounter++;
                    return 
            $row[0];
                  } else {
                    
            // query returned no data
                    
            return -1;
                  }
                } else {
                  
            $this->printerror($this->mysqli->error);
                  return -
            1;
                }
              }

              
            // execute a query which returns row
              // beware: this method return -1 for errors (not 0)!
              
            function queryRow($sql$file 'not'$line 'set') {
                
            $this->sqlcounter++;
                
            $time1  $this->microtime_float();
                
            $result $this->mysqli->query($sql);
                
            $time2  $this->microtime_float();
                
            $ttime  = ($time2 $time1);
                
            $this->printsql($sql,$ttime$file$line);
                
            //$this->dbtime += ($time2 - $time1);
                
            $this->dbtime += $ttime;
                if(
            $result) {
                  return 
            $result;
                } else {
                  
            $this->printerror($this->mysqli->error);
                  return -
            1;
                }
              }
             
              
            // execute a SQL command without results (no query)
              
            function execute($sql$file 'not'$line 'set') {
                
            $this->sqlcounter++;
                
            $time1  $this->microtime_float();
                
            $result $this->mysqli->real_query($sql);
                
            $time2  $this->microtime_float();
                
            $ttime  = ($time2 $time1);
                
            $this->printsql($sql,$ttime$file$line);
                
            //$this->dbtime += ($time2 - $time1);
                
            $this->dbtime += $ttime;
                if(
            $result)
                  return 
            TRUE;
                else {
                  
            $this->printerror($this->mysqli->error);
                  return 
            FALSE;
                }
              }
              
              function 
            getVersion() {
                 return 
            $this->mysqli->server_info;
              }

              function 
            numRows($sql) {
                 return 
            $sql->num_rows;
              }

              function 
            fetchAssoc($sql) {
                 return 
            $sql->fetch_assoc();
              }

              function 
            fetchArray($sql) {
                 return 
            $sql->fetch_array(MYSQLI_BOTH);
              }

              
            // get insert_id after an INSERT command
              
            function insertId() {
                return 
            $this->mysqli->insert_id; }
             
              
            // insert \ before ', " etc.
              
            function escape($txt) {
                return 
            trim($this->mysqli->escape_string($txt)); }
             
              
            // return 'NULL' or '<quoted string>'
              
            function sql_string($txt) {
                if(!
            $txt || trim($txt)=="")
                  return 
            'NULL';
                else
                  return 
            "'" $this->escape(trim($txt)) . "'";  }
             
              function 
            error() {
                return 
            $this->mysqli->error; }
             
               function 
            printsql($sql,$time,$file,$line) {
                if(
            $this->showsql)
               
            //  printf("<p><font color=\"#00aa00\">%s</font></p>\n",
               //  htmlentities($sql)); 
               
            {
                   
            $this->showsqls['seconds'][] = (float)$time;
                   
            $this->showsqls['query'][] = $sql;
                   
            $this->showsqls['file'][] = $file;
                   
            $this->showsqls['line'][] = $line;
               } 
             
            }
             
               function 
            debug() {
             
                  for(
            $i=0$i count($this->showsqls['query']); $i++){

                
            $info substr($this->showsqls['file'][$i],strlen($_SERVER["DOCUMENT_ROOT"])+1);


                
            printf("[".($i+1)."] => <b>
                       "
            .($this->showsqls['seconds'][$i] > 0.01 
                       
            "<font color=\"red\" title=\"BAD QRY.\">".$this->showsqls['seconds'][$i]."</font>" 
                       
            "<font color=\"green\" title=\"GOOD QRY.\">%f</font>" )."</b> 
                      ["
            .$this->showsqls['query'][$i]."] 
                    <img src=\"/design/main/modernblue/images/b_tipp.gif\"  width=\"10\" height=\"10\" id=\"trigger"
            .($i+1)."\"></img>
                        <div class=\"tooltip\">
                    Ort: 
            $info <br />
                    Zeile: "
            .$this->showsqls['line'][$i]." <br />
                    Zeit: %f<br />
                    Optimieren: "
            .($this->showsqls['seconds'][$i] > 0.01 "<font color=\"red\">Notwendig</font>" 
                                                   
            "<font color=\"green\">Nicht notwendig</font>")."
                    </div><script type=\"text/javascript\">$(function() { $(\"#trigger"
            .($i+1)."\").tooltip(); });</script>
                    <br />\n"
            ,$this->showsqls['seconds'][$i],$this->showsqls['seconds'][$i]);

                }
                print(
            "<br />");

                    
            $totalTime $this->microtime_float() - $this->starttime;
                
            printf("<p><font color=\"#0000ff\">SQL commands: %d\n",
                
            $this->sqlcounter);
                
            printf("<br />Sum of returned rows: %d\n",
                
            $this->rowcounter);
                
            printf("<br />Sum of query time (MySQL): %f\n",
                
            $this->dbtime);
                
            printf("<br />Processing time (PHP): %f\n",
                
            $totalTime $this->dbtime);
                
            printf("<br />Total time since MyDB creation / last reset: %f</font></p>\n",
                
            $totalTime);
            }

              private function 
            printerror($txt) {
                if(
            $this->showerror)
                  
            printf("<p><font color=\"#ff0000\">%s</font></p>\n",
                    
            htmlentities($txt));  
                }
             
              function 
            resetStatistics() {
                
            $this->sqlcounter 0;
                
            $this->rowcounter 0;
                
            $this->dbtime     0;
                
            $this->starttime $this->microtime_float();  }
             
              private function 
            microtime_float() {
                list(
            $usec$sec) = explode(" "microtime());
                return ((float)
            $usec + (float)$sec); }
             
            }
            </b>

            könnt ihr mir mal weiterhelfen?





            Kommentar

            Lädt...
            X