Ankündigung

Einklappen
Keine Ankündigung bisher.

Datenbank Class fehler

Einklappen

Neue Werbung 2019

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

  • Datenbank Class fehler

    Hallo PHP Community,
    Folgendes : ich habe das Script übernommen wie es im Thread stand ( http://www.html-seminar.de/html-css-...thread-script/ )

    In der Class sektor => select();
    Sobald ich etwas ausgeben möchte kommen fehler sofern es mehr als 1 Eintrag in der DB gibt.

    Wie hier zu sehen => http://www.bilder-upload.eu/show.php...1480978630.png ist dass das Script wo er eine Abfrage stellt.
    Hier der Sektor => select(); =>http://www.bilder-upload.eu/show.php...1480978685.png
    Oben der komplette link zur Class!
    Hier die fehler meldung wenn mehr als 1 Eintrag existiert => http://www.bilder-upload.eu/show.php...1480978767.png
    Und hier, wenn nur 1 Eintrag existiert => http://www.bilder-upload.eu/show.php...1480978793.png

    Ich würde mich um Hilfe freuen.

    Lg Fabian

  • #2
    Kannst du bitte Code und Fehlermeldungen als Text und nicht als Screenshot posten?
    [QUOTE=nikosch]Macht doch alle was Ihr wollt mit Eurem Billigscheiß. Von mir aus sollen alle Eure Server abrauchen.[/QUOTE]

    Kommentar


    • #3
      Könnte ich ja, aber es wäre zu viel zu lesen aber mach ich :

      Hier die Datenbank.php (class)
      PHP-Code:
      <?php 
          
      class DB {

              public static 
      $db null;

              public static 
      $insertID;

              public static function 
      init($dbHost$dbUser$dbPassword$dbName) {
                  
      self::$db = new mysqli($dbHost$dbUser$dbPassword$dbName);
                  if (
      self::$db->connect_errno) {
                      echo 
      "<p style='color:red'>Datenbank Offline</p>";
                      Exit;
                  }
                  
      self::$db->query("SET NAMES utf8;");
              } 
      // DATENBANK CONNECT

              
      public static function query($sql$debug false) {
                  
      $result self::$db->query($sql);
                  if (
      $debug == true) {
                      
      $_SESSION['debug'][] = __FUNCTION__ ': $sql is <strong>'.$sql.'</strong>';
                  }
                  if (
      self::$db->errno) {
                      
      $_SESSION['errors'][] = "<p>insert failed: " self::$db->error "<br> statement was: <strong> $sql </strong></p>";
                  }
                  return 
      $result;
              }

              public static function 
      insert($table$data$debug false) {
                  
      $keys ""$values "";
                  foreach (
      $data as $key => $value) {
                      
      $key self::escape($key);
                      
      $value self::escape($value);
                      
      $keys .= $key ", ";
                      if (
      $value == null) {
                          
      $values .= "null, ";
                      }
                      else {
                          
      $values .= "'" $value "', ";
                      }
                  }
                  
      $keys rtrim($keys', ');
                  
      $values rtrim($values', ');

                  
      $sql "INSERT INTO $table (" $keys ") VALUES (" $values ")";

                  if (
      $debug == true) {
                      
      $_SESSION['debug'][] = __FUNCTION__ ': $sql is <strong>' $sql '</strong>';
                  }

                  
      self::$db->query($sql);

                  if (
      self::$db->errno) {
                      
      $_SESSION['errors'][] = '<p>' __FUNCTION__ ' failed: ' self::$db->error '<br> statement was: <strong> ' $sql '</strong></p>';
                  }

                  
      self::$insertID self::$db->insert_id;
              } 
      // IDATENBANK INSERT

              
      public static function update($table$id$data$debug false) {
                  
      $sql "UPDATE $table SET ";
                  foreach (
      $data as $key => $value) {
                      
      $key self::escape($key);
                      
      $value self::escape($value);
                      if (
      $value == null) {
                          
      $sql .= "$key = null, ";
                      } else {
                          
      $sql .= "$key = '$value', ";
                      }
                  }

                  
      $sql rtrim($sql", ");

                  
      $sql .= " WHERE " self::getPrimaryKeyColumn($table) . " = $id";

                  if (
      $debug == true) {
                      
      $_SESSION['debug'][] = __FUNCTION__ ': $sql is <strong>' $sql '</strong>';
                  }

                  
      self::$db->query($sql);

                  if (
      self::$db->errno) {
                      
      $_SESSION['errors'][] = '<p>' __FUNCTION__ ' failed: ' self::$db->error '<br> statement was: <strong> ' $sql '</strong></p>';
                  }
              } 
      //DATENBANK UPDATE

              
      public static function select($table$columns '*'$where null$limit null$debug false) {
                  
      $sql "SELECT " self::generateColumnList($columns) . " FROM $table";
                  if (
      $where != null) {
                      
      $sql .= " WHERE ".$where;
                  }
                  if (
      $limit != null) {
                      
      $sql .= " LIMIT ".$limit;
                  }
                  if (
      $debug == true) {
                      
      $_SESSION['debug'][] = __FUNCTION__ ': $sql is <strong>' $sql '</strong>';
                  }

                  
      $result self::$db->query($sql);
                  if (
      self::$db->errno) {
                      
      $_SESSION['errors'][] = '<p>select failed: ' self::$db->error '<br> statement was: <strong>' $sql '</strong></p>';
                      return array();
                  } else {
                      
      $ret = array();
                      while (
      $row $result->fetch_object()) {
                          
      $ret[] = $row;
                      }
                      if (
      count($ret) == 1) {
                          return 
      $ret[0];
                      } else {
                          return 
      $ret;
                      }
                  }
              }

              public static function 
      deletes($table$id$debug false) {
                  
      $sql "DELETE FROM $table WHERE " self::getPrimaryKeyColumn($table) . " = $id";

                  if (
      $debug == true) {
                      
      $_SESSION['debug'][] = __FUNCTION__ ': $sql is <strong>' $sql '</strong>';
                  }

                  
      self::$db->query($sql);

                  if (
      self::$db->errno) {
                      
      $_SESSION['errors'][] = '<p>' __FUNCTION__ ' failed: ' self::$db->error '<br> statement was: <strong>' $sql '</strong></p>';
                  }
              }

              public static function 
      escape($string) {
                  return 
      self::$db->real_escape_string($string);
              }

              public static function 
      getPrimaryKeyColumn($table$debug false) {
                  
      $sql "SHOW KEYS FROM $table WHERE key_name = 'PRIMARY'";

                  if (
      $debug == true) {
                      
      $_SESSION['debug'][] = __FUNCTION__ ': $sql is <strong>' $sql '</strong>';
                  }

                  
      $result self::$db->query($sql);

                  while (
      $row $result->fetch_assoc()) {
                      return 
      $row['Column_name'];
                  }

                  if (
      self::$db->errno) {
                      
      $_SESSION['errors'][] = '<p>' __FUNCTION__ ' failed: ' self::$db->error '<br> statement was: <strong>' $sql '</strong></p>';
                  }

                  return 
      false;
              }

              private static function 
      generateColumnList($columns) {
                  if (
      is_array($columns)) {
                      return 
      implode(', '$columns);
                  } else {
                      return 
      $columns;
                  }

              }
          }
      ?>
      Und hier mein Script:

      PHP-Code:
      <div class='widget-box'>
          <div class='widget-title bg_lo' data-toggle='collapse' href='#collapseG3'> <span class='icon'> <i class='icon-chevron-down'></i> </span>
              <h5>Updates</h5>
          </div>

          <div class='widget-content nopadding updates collapse in' id='collapseG3'>
              <?php

                  $sel 
      $db->select('updates','*','',20,false);
                  
      $select = array($sel->betreff$sel->text$sel->datum); 
                      echo 
      "
                          <div class='new-update clearfix'><i class='icon-ok-sign'></i>
                              <div class='update-done'><a title='' href='#'><strong>
      $select[0]</strong></a> <span>$select[1]</span> </div>
                              <div class='update-date'><span class='update-day'>
      $select[2]</span></div>
                          </div>
                      "
      ;
              
      ?>
          </div>
      </div>
      Die Fehler meldung :

      PHP-Code:
      NoticeTrying to get property of non-object in new\inc\interface\sites\dashboard.php on line 10

      Notice
      Trying to get property of non-object in new\inc\interface\sites\dashboard.php on line 10

      Notice
      Trying to get property of non-object in new\inc\interface\sites\dashboard.php on line 10 
      Und zuletzt die Index.php // Aufbau der Datenbank e.t.c.
      PHP-Code:
      <?php
          
      Include 'inc/func/all.php';
          
      //error_reporting(0);

          
      $db = NEW DB;
          
      $db->init("Localhost","root","","webinterface");

          Include 
      'inc/interface/index.php';
      ?>
      Lg, Fabian

      Kommentar


      • #4
        $sel ist ein array, kein objekt.
        [QUOTE=nikosch]Macht doch alle was Ihr wollt mit Eurem Billigscheiß. Von mir aus sollen alle Eure Server abrauchen.[/QUOTE]

        Kommentar


        • #5
          Ob ich es in einem array schreibe oder nur $sel->betreff spielt keine rolle, beides geht nicht, selber fehler

          Kommentar


          • #6
            Zitat von Nazatrika Beitrag anzeigen
            Könnte ich ja, aber es wäre zu viel zu lesen aber mach ich :
            Ich hätte zB auf die Links gar nicht geklickt. Alles was man braucht / wichtig ist kann man hier posten.


            Code:
            Notice: Trying to get property of non-object in new\inc\interface\sites\dashboard.php on line 10
            
            Notice: Trying to get property of non-object in new\inc\interface\sites\dashboard.php on line 10
            
            Notice: Trying to get property of non-object in new\inc\interface\sites\dashboard.php on line 10

            PHP-Code:
            $sel $db->select('updates','*','',20,false);
            $select = array($sel->betreff$sel->text$sel->datum); ## vermutlich ist das zeile 10? 

            Dreh mal error_reporting hoch. http://php.net/manual/de/mysqli.error.php
            The string "()()" is not palindrom but the String "())(" is.

            Debugging: Finde DEINE Fehler selbst! | Gegen Probleme beim E-Mail-Versand | Sicheres Passwort-Hashing | Includes niemals ohne __DIR__
            PHP.de Wissenssammlung | Kein Support per PN

            Kommentar


            • #7
              Kommen selbe fehler meldung
              Soweit gibt es keine fehler mit der mysql

              Es hängt rein mit der $sel-> zusammen, aber was ich nicht verstehe wieso...
              Wenn ich eine verbindung schreibe und es mit $row = mysql_fetch_object($string); mache, geht alles einwandfrei ...
              Sogar while geht.. aber so wie es jetzt ist und ich while setze, flutet er mir alles zu...

              Kommentar


              • #8
                Achso.. ja schau in die Klasse.. Die Methode select gibt schon ein Array zurück und kein Objekt. Dh $sel ist ein Array, wie oben schon von tkausl erwähnt.
                The string "()()" is not palindrom but the String "())(" is.

                Debugging: Finde DEINE Fehler selbst! | Gegen Probleme beim E-Mail-Versand | Sicheres Passwort-Hashing | Includes niemals ohne __DIR__
                PHP.de Wissenssammlung | Kein Support per PN

                Kommentar


                • #9
                  Könntest du die Skripte posten, welche auch den Fehler bringen? Deine Fehlermeldung resultiert aus einer dashboard.php, die taucht aber sonst nicht auf.
                  Hast du die dashboard.php etwa direkt im Browser aufgerufen?

                  Kommentar


                  • #10
                    Nein, die Dashboard.php wird über einem parameter aufgerufen index.php?dashboard=/

                    Und das steht in der Dashboard.php

                    PHP-Code:
                    <div class='widget-box'>
                        <div class='widget-title bg_lo' data-toggle='collapse' href='#collapseG3'> <span class='icon'> <i class='icon-chevron-down'></i> </span>
                            <h5>Updates</h5>
                        </div>

                        <div class='widget-content nopadding updates collapse in' id='collapseG3'>
                            <?php

                                $sel 
                    $db->select('updates','*','',20,false);
                                
                    $select = array($sel->betreff$sel->text$sel->datum); 
                                    echo 
                    "
                                        <div class='new-update clearfix'><i class='icon-ok-sign'></i>
                                            <div class='update-done'><a title='' href='#'><strong>
                    $select[0]</strong></a> <span>$select[1]</span> </div>
                                            <div class='update-date'><span class='update-day'>
                    $select[2]</span></div>
                                        </div>
                                    "
                    ;
                            
                    ?>
                        </div>
                    </div>
                    Ja, wie soll ich dann die werte abfangen? Wie gesagt, wenn nur ein eintrag in der DB drine ist, wird mir der angezeigt sowohl mit array auch ohne array...

                    Kommentar


                    • #11
                      Kann es auch Live zeigen via Skype oder Tv11 / Tv12 falls es jemand erleichtern sollte, bzw. kann ich es besser erklären

                      Kommentar


                      • #12
                        Ja, wie soll ich dann die werte abfangen?
                        Mach bitte mal:

                        PHP-Code:
                        $sel $db->select('updates','*','',20,false);
                        //$select = array($sel->betreff, $sel->text, $sel->datum);

                        print_r($sel);
                        // alternativ var_dump($sel); 
                        Und schau die Ausgabe an.

                        Dann solltest du mit $sel['betreff'] auch normal darauf zugreifen können.. Wo ist das Problem?
                        The string "()()" is not palindrom but the String "())(" is.

                        Debugging: Finde DEINE Fehler selbst! | Gegen Probleme beim E-Mail-Versand | Sicheres Passwort-Hashing | Includes niemals ohne __DIR__
                        PHP.de Wissenssammlung | Kein Support per PN

                        Kommentar


                        • #13
                          Ausgaben:
                          PHP-Code:
                          Array ( [0] => stdClass Object ( [id] => [betreff] => Test [text] => Hallo [datum] => Heute [sys] => ) [1] => stdClass Object ( [id] => [betreff] => Test [text] => Hallo [datum] => Heute [sys] => ) [2] => stdClass Object ( [id] => [betreff] => Test [text] => Hallo [datum] => Heute [sys] => ) ) 

                          Kommentar


                          • #14
                            Jo ist ein Array mit Objekten. Dh. $sel[0]->betreff etc.. bzw. mit foreach() über das Array iterieren (durchlaufen).
                            The string "()()" is not palindrom but the String "())(" is.

                            Debugging: Finde DEINE Fehler selbst! | Gegen Probleme beim E-Mail-Versand | Sicheres Passwort-Hashing | Includes niemals ohne __DIR__
                            PHP.de Wissenssammlung | Kein Support per PN

                            Kommentar


                            • #15
                              Und jetzt für doofies xD

                              Kommentar

                              Lädt...
                              X