Ankündigung

Einklappen
Keine Ankündigung bisher.

[Erledigt] PDO fetch geht bei dem ersten Objekt nicht richtig

Einklappen

Neue Werbung 2019

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

  • [Erledigt] PDO fetch geht bei dem ersten Objekt nicht richtig

    Guten Abend / Nacht liebe Community,

    ich sitze nun mehr als zwei Stunden an einem Projekt und bekomme immer einen Fehler, den ich nicht mehr beheben kann, was mich sehr stört.

    Ich habe mehrere Klassen erstellt, um einen Player abbilden zu können ,der mehrere Charaktere beinhaltet. Jeder dieser Charaktere hat dann wiederum
    zum einen Skills und Items, die er erhalten kann. Aufgrund dessen habe ich eine Klasse "Player" erstellt, danach die Klasse "Char", "CharItem" und "CharSkills". Nunja die Datenbankabfragen funktionieren alle, blos sie werden nicht wirklich richtig gefetcht.
    Ich hoffe mal das mir jemand schnell weiter helfen kann.
    Im Grunde genommen geht es mir nur um die Funktionen setSkills und setItems. Aber da man nunmal mehr Informationen benötigt, um das Ganze sehen zu können schicke ich einfach mal alles mit. Das Komische ist wirklich nur das nicht der erste Wert, etc mitgenommen werden. Falls mir dort jemand einen Tipp geben kann wie dieser fetch-Fehler auftreten kann währe das wirklich perfekt, da ich momentan wirklich daran verzweifel.

    Diese Klassen werden in einem bestimmten File aufgerufen:
    PHP-Code:
    <?php
    if (isset($_POST['username'])) {
        
    $username $_POST['username'];
    }
    if (isset(
    $_POST['password'])) {
        
    $password $_POST['password'];
    }
    if (isset(
    $_POST['login'])) {
        
    $login $_POST['login'];
    }
    // put it in the session from the player!
    if (!empty($login)) {
        
    $_SESSION['IP'] = $_SERVER['REMOTE_ADDR'];
        
    $IP $_SESSION['IP'];
        
    $resPlayer $kal_auth->dbStatement("SELECT * FROM dbo.Login WHERE ID=? AND MD5PW=?", array($usernamemd5(htmlentities($password))));
        if (
    abs($resPlayer->rowCount()) > 0) {
            
    $rowPlayer $resPlayer->fetch(PDO::FETCH_ASSOC);
            
    $kal_auth->dbStatement("INSERT INTO dbo.user_logindata (ID, LoginTime, LogoutTime, CurrentTime,IP,sessionId) "
                    
    "             VALUES (?,?,?,?,?,?)", array($rowPlayer['ID'],
                
    toolbox::getCurrentTime()->format("Y-m-d H:i:s"),
                
    toolbox::getCurrentTime()->format("Y-m-d H:i:s"),
                
    toolbox::getCurrentTime()->format("Y-m-d H:i:s"),
                
    $IP,
                
    $session_id));
            
    $_SESSION['Player'] = new player($kal_db$kal_auth$rowPlayer['UID'], $rowPlayer['ID'], $rowPlayer['PWD'], $rowPlayer['MD5PW'], $rowPlayer['EMAIL'], $rowPlayer['IP'], $rowPlayer['SN'], $rowPlayer['Admin']);
        }
    }
    if (isset(
    $_SESSION['Player'])) {
        
    $login_ok true;
    }
    if (!empty(
    $_GET['logout'])) {
        
    // LogoutTime aktualisieren mit der LoginID
        
    $kal_auth->dbStatement("UPDATE user_logindata SET LogoutTime=? WHERE AutoID=? ORDER BY AutoID DESC", array(toolbox::getCurrentTime()->format("Y-m-d"), $_SESSION['LoginID']));
        unset(
    $_SESSION);
        
    unserialize($Player);
        
    session_destroy();
        
    $login_ok false;
        echo 
    '<meta http-equiv="refresh" content="0; url=index.php">';
    }
    ?>
    Die Player Klasse:
    PHP-Code:
    <?php

    include "Models/Char.php";

    class 
    player {

        private 
    $charArray = array();
        private 
    $uid;
        private 
    $id;
        private 
    $pwd;
        private 
    $md5pw;
        private 
    $email;
        private 
    $ip;
        private 
    $sn;
        private 
    $admin;
        private 
    $kal_db;
        private 
    $kal_auth;

        public function 
    __construct($kal_db$kal_auth$uid$id$pwd$md5pw$email$ip$sn$admin) {
            
    $this->kal_db $kal_db;
            
    $this->kal_auth $kal_auth;
            
    $this->uid $uid;
            
    $this->id $id;
            
    $this->pwd $pwd;
            
    $this->md5pw $md5pw;
            
    $this->email $email;
            
    $this->ip $ip;
            
    $this->sn $sn;
            
    $this->admin $admin;
            
    $this->setChars();
        }

        private function 
    setChars() {
            
    $resChars $this->kal_db->dbStatement("SELECT * FROM dbo.Player WHERE UID=?", array($this->getUid()));
            while (
    $rowChars $resChars->fetch(PDO::FETCH_ASSOC)) {
                
    $this->charArray[$rowChars['Name']] = new char($this->kal_db,$this->kal_auth,$rowChars['UID'], $rowChars['PID'], $rowChars['Admin'], $rowChars['Name'], $rowChars['Class'], $rowChars['Specialty'], $rowChars['Level'], $rowChars['Contribute'], $rowChars['Exp'], $rowChars['GID'], $rowChars['GRole'], $rowChars['Strength'], $rowChars['Health'], $rowChars['Intelligence'], $rowChars['Wisdom'], $rowChars['Dexterity'], $rowChars['CurHP'], $rowChars['CurMP'], $rowChars['PUPoint'], $rowChars['SUPoint'], $rowChars['Killed'], $rowChars['Map'], $rowChars['X'], $rowChars['Y'], $rowChars['Z'], $rowChars['Face'], $rowChars['Hair'], $rowChars['RevivalId'], $rowChars['Rage'], $rowChars['Reborn'], $rowChars['GM']);
            }
        }

        function 
    getCharArray() {
            return 
    $this->charArray;
        }

        function 
    getPwd() {
            return 
    $this->pwd;
        }

        function 
    getUid() {
            return 
    $this->uid;
        }

        function 
    getId() {
            return 
    $this->id;
        }

        function 
    getMd5pw() {
            return 
    $this->md5pw;
        }

        function 
    getEmail() {
            return 
    $this->email;
        }

        function 
    getIp() {
            return 
    $this->ip;
        }

        function 
    getSn() {
            return 
    $this->sn;
        }

        function 
    getAdmin() {
            return 
    $this->admin;
        }

        function 
    setCharArray($charArray) {
            
    $this->charArray $charArray;
        }

        function 
    setPwd($pwd) {
            
    $this->pwd $pwd;
        }

        function 
    setUid($uid) {
            
    $this->uid $uid;
        }

        function 
    setId($id) {
            
    $this->id $id;
        }

        function 
    setMd5pw($md5pw) {
            
    $this->md5pw $md5pw;
        }

        function 
    setEmail($email) {
            
    $this->email $email;
        }

        function 
    setIp($ip) {
            
    $this->ip $ip;
        }

        function 
    setSn($sn) {
            
    $this->sn $sn;
        }

        function 
    setAdmin($admin) {
            
    $this->admin $admin;
        }

    }

    ?>
    Die Char-Klasse
    PHP-Code:
    <?php
    include "Models/CharItems.php";
    include 
    "Models/CharSkills.php";
    class 
    char {
        private 
    $skillArray = array();
        private 
    $itemArray = array();
        private 
    $kal_db;
        private 
    $kal_auth;
        private 
    $uid;
        private 
    $pid;
        private 
    $admin;
        private 
    $name;
        private 
    $class;
        private 
    $specialty;
        private 
    $level;
        private 
    $cp;
        private 
    $exp;
        private 
    $gid;
        private 
    $grole;
        private 
    $str;
        private 
    $hth;
        private 
    $int;
        private 
    $wis;
        private 
    $dex;
        private 
    $curhp;
        private 
    $curmp;
        private 
    $pu;
        private 
    $su;
        private 
    $killed;
        private 
    $map;
        private 
    $x;
        private 
    $y;
        private 
    $z;
        private 
    $face;
        private 
    $hair;
        private 
    $revivalid;
        private 
    $rage;
        private 
    $reborn;
        private 
    $gm;

        public function 
    __construct($kal_db$kal_auth$uid$pid$admin$name$class$specialty$level$cp$exp$gid$grole$str$hth$int$wis$dex$curhp$curmp$pu$su$killed$map$x$y$z$face$hair$revivalid$rage$reborn$gm) {
            
    $this->kal_db $kal_db;
            
    $this->kal_auth $kal_auth;
            
    $this->uid $uid;
            
    $this->pid $pid;
            
    $this->admin $admin;
            
    $this->name $name;
            
    $this->class $class;
            
    $this->specialty $specialty;
            
    $this->level $level;
            
    $this->cp $cp;
            
    $this->exp $exp;
            
    $this->gid $gid;
            
    $this->grole $grole;
            
    $this->str $str;
            
    $this->hth $hth;
            
    $this->int $int;
            
    $this->wis $wis;
            
    $this->dex $dex;
            
    $this->curhp $curhp;
            
    $this->curmp $curmp;
            
    $this->pu $pu;
            
    $this->se $su;
            
    $this->killed $killed;
            
    $this->map $map;
            
    $this->$x;
            
    $this->$y;
            
    $this->$z;
            
    $this->face $face;
            
    $this->hair $hair;
            
    $this->revivalid $revivalid;
            
    $this->rage $rage;
            
    $this->reborn $reborn;
            
    $this->gm $gm;
            
    $this->setSkills();
            
    $this->setItems();
        }

        private function 
    setSkills() {
            
    $resSkills $this->kal_db->dbStatement("SELECT * FROM dbo.Skill WHERE PID=?", array($this->getPid()));
            while (
    $rowSkills $resSkills->fetch(PDO::FETCH_ASSOC)) {
                
    $this->skillArray[] = new charskills($rowSkills['PID'], $rowSkills['Index'], $rowSkills['Level']);
            }
        }

        public function 
    setItems() {
            
    $resItems $this->kal_db->dbStatement("SELECT * FROM dbo.Item WHERE PID=?", array($this->getPid()));
            while (
    $rowItems $resItems->fetch(PDO::FETCH_ASSOC)) {
                
    $this->itemArray[] = new charitems($rowItems['PID'], $rowItems['IID'], $rowItems['Index'], $rowItems['Prefix'], $rowItems['Info'], $rowItems['Num'], $rowItems['MaxEnd'], $rowItems['CurEnd'], $rowItems['SetGem'], $rowItems['XAttack'], $rowItems['XMagic'], $rowItems['XDefense'], $rowItems['XHit'], $rowItems['XDodge'], $rowItems['Protect'], $rowItems['UpgrLevel'], $rowItems['UpgrRate']);
            }
        }

        function 
    getItemArray() {
            return 
    $this->itemArray;
        }

        function 
    getSkillArray() {
            return 
    $this->skillArray;
        }

        function 
    getUid() {
            return 
    $this->uid;
        }

        function 
    getPid() {
            return 
    $this->pid;
        }

        function 
    getAdmin() {
            return 
    $this->admin;
        }

        function 
    getName() {
            return 
    $this->name;
        }

        function 
    getClass() {
            return 
    $this->class;
        }

        function 
    getSpecialty() {
            return 
    $this->specialty;
        }

        function 
    getLevel() {
            return 
    $this->level;
        }

        function 
    getCp() {
            return 
    $this->cp;
        }

        function 
    getExp() {
            return 
    $this->exp;
        }

        function 
    getGid() {
            return 
    $this->gid;
        }

        function 
    getGrole() {
            return 
    $this->grole;
        }

        function 
    getStr() {
            return 
    $this->str;
        }

        function 
    getHth() {
            return 
    $this->hth;
        }

        function 
    getInt() {
            return 
    $this->int;
        }

        function 
    getWis() {
            return 
    $this->wis;
        }

        function 
    getDex() {
            return 
    $this->dex;
        }

        function 
    getCurhp() {
            return 
    $this->curhp;
        }

        function 
    getCurmp() {
            return 
    $this->curmp;
        }

        function 
    getPu() {
            return 
    $this->pu;
        }

        function 
    getSu() {
            return 
    $this->su;
        }

        function 
    getKilled() {
            return 
    $this->killed;
        }

        function 
    getMap() {
            return 
    $this->map;
        }

        function 
    getX() {
            return 
    $this->x;
        }

        function 
    getY() {
            return 
    $this->y;
        }

        function 
    getZ() {
            return 
    $this->z;
        }

        function 
    getFace() {
            return 
    $this->face;
        }

        function 
    getHair() {
            return 
    $this->hair;
        }

        function 
    getRevivalid() {
            return 
    $this->revivalid;
        }

        function 
    getRage() {
            return 
    $this->rage;
        }

        function 
    getReborn() {
            return 
    $this->reborn;
        }

        function 
    getGm() {
            return 
    $this->gm;
        }

        function 
    setItemArray($itemArray) {
            
    $this->itemArray $itemArray;
        }

        function 
    setSkillArray($skillArray) {
            
    $this->skillArray $skillArray;
        }

        function 
    setUid($uid) {
            
    $this->uid $uid;
        }

        function 
    setPid($pid) {
            
    $this->pid $pid;
        }

        function 
    setAdmin($admin) {
            
    $this->admin $admin;
        }

        function 
    setName($name) {
            
    $this->name $name;
        }

        function 
    setClass($class) {
            
    $this->class $class;
        }

        function 
    setSpecialty($specialty) {
            
    $this->specialty $specialty;
        }

        function 
    setLevel($level) {
            
    $this->level $level;
        }

        function 
    setCp($cp) {
            
    $this->cp $cp;
        }

        function 
    setExp($exp) {
            
    $this->exp $exp;
        }

        function 
    setGid($gid) {
            
    $this->gid $gid;
        }

        function 
    setGrole($grole) {
            
    $this->grole $grole;
        }

        function 
    setStr($str) {
            
    $this->str $str;
        }

        function 
    setHth($hth) {
            
    $this->hth $hth;
        }

        function 
    setInt($int) {
            
    $this->int $int;
        }

        function 
    setWis($wis) {
            
    $this->wis $wis;
        }

        function 
    setDex($dex) {
            
    $this->dex $dex;
        }

        function 
    setCurhp($curhp) {
            
    $this->curhp $curhp;
        }

        function 
    setCurmp($curmp) {
            
    $this->curmp $curmp;
        }

        function 
    setPu($pu) {
            
    $this->pu $pu;
        }

        function 
    setSu($su) {
            
    $this->su $su;
        }

        function 
    setKilled($killed) {
            
    $this->killed $killed;
        }

        function 
    setMap($map) {
            
    $this->map $map;
        }

        function 
    setX($x) {
            
    $this->$x;
        }

        function 
    setY($y) {
            
    $this->$y;
        }

        function 
    setZ($z) {
            
    $this->$z;
        }

        function 
    setFace($face) {
            
    $this->face $face;
        }

        function 
    setHair($hair) {
            
    $this->hair $hair;
        }

        function 
    setRevivalid($revivalid) {
            
    $this->revivalid $revivalid;
        }

        function 
    setRage($rage) {
            
    $this->rage $rage;
        }

        function 
    setReborn($reborn) {
            
    $this->reborn $reborn;
        }

        function 
    setGm($gm) {
            
    $this->gm $gm;
        }

    }

    ?>
    Die Skill-Klasse:
    PHP-Code:
    <?php
    class charskills {
        private 
    $pid;
        private 
    $index;
        private 
    $level;
        public function 
    __construct($pid,$index,$level) {
            
    $this->pid $pid;
            
    $this->index $index;
            
    $this->level $level;
        }
            function 
    getPid() {
                return 
    $this->pid;
            }

            function 
    getIndex() {
                return 
    $this->index;
            }

            function 
    getLevel() {
                return 
    $this->level;
            }

            function 
    setPid($pid) {
                
    $this->pid $pid;
            }

            function 
    setIndex($index) {
                
    $this->index $index;
            }

            function 
    setLevel($level) {
                
    $this->level $level;
            }
    }
    ?>
    Die Item-Klasse:
    PHP-Code:
    <?php
    class charitems {
        private 
    $pid;
        private 
    $iid;
        private 
    $index;
        private 
    $prefix;
        private 
    $info;
        private 
    $num;
        private 
    $maxend;
        private 
    $curend;
        private 
    $setgem;
        private 
    $xattack;
        private 
    $xmagic;
        private 
    $xdefense;
        private 
    $xhit;
        private 
    $xdodge;
        private 
    $protect;
        private 
    $upgrlevel;
        private 
    $upgrrate;
        public function 
    __construct($pid,$iid,$index,$prefix,$info,$num,$maxend,$curend,$setgem,$xattack,$xmagic,$xdefense,$xhit,$xdodge,$protect,$upgrlevel,$upgrrate){
            
    $this->pid $pid;
            
    $this->iid $iid;
            
    $this->index $index;
            
    $this->prefix $prefix;
            
    $this->info $info;
            
    $this->num $num;
            
    $this->maxend $maxend;
            
    $this->curend $curend;
            
    $this->setgem $setgem;
            
    $this->xattack $xattack;
            
    $this->xmagic $xmagic;
            
    $this->xdefense $xdefense;
            
    $this->xhit $xhit;
            
    $this->xdodge $xdodge;
            
    $this->protect $protect;
            
    $this->upgrlevel $upgrlevel;
            
    $this->upgrrate $upgrrate;
        }
            function 
    getPid() {
                return 
    $this->pid;
            }

            function 
    getIid() {
                return 
    $this->iid;
            }

            function 
    getIndex() {
                return 
    $this->index;
            }

            function 
    getPrefix() {
                return 
    $this->prefix;
            }

            function 
    getInfo() {
                return 
    $this->info;
            }

            function 
    getNum() {
                return 
    $this->num;
            }

            function 
    getMaxend() {
                return 
    $this->maxend;
            }

            function 
    getCurend() {
                return 
    $this->curend;
            }

            function 
    getSetgem() {
                return 
    $this->setgem;
            }

            function 
    getXattack() {
                return 
    $this->xattack;
            }

            function 
    getXmagic() {
                return 
    $this->xmagic;
            }

            function 
    getXdefense() {
                return 
    $this->xdefense;
            }

            function 
    getXhit() {
                return 
    $this->xhit;
            }

            function 
    getXdodge() {
                return 
    $this->xdodge;
            }

            function 
    getProtect() {
                return 
    $this->protect;
            }

            function 
    getUpgrlevel() {
                return 
    $this->upgrlevel;
            }

            function 
    getUpgrrate() {
                return 
    $this->upgrrate;
            }

            function 
    setPid($pid) {
                
    $this->pid $pid;
            }

            function 
    setIid($iid) {
                
    $this->iid $iid;
            }

            function 
    setIndex($index) {
                
    $this->index $index;
            }

            function 
    setPrefix($prefix) {
                
    $this->prefix $prefix;
            }

            function 
    setInfo($info) {
                
    $this->info $info;
            }

            function 
    setNum($num) {
                
    $this->num $num;
            }

            function 
    setMaxend($maxend) {
                
    $this->maxend $maxend;
            }

            function 
    setCurend($curend) {
                
    $this->curend $curend;
            }

            function 
    setSetgem($setgem) {
                
    $this->setgem $setgem;
            }

            function 
    setXattack($xattack) {
                
    $this->xattack $xattack;
            }

            function 
    setXmagic($xmagic) {
                
    $this->xmagic $xmagic;
            }

            function 
    setXdefense($xdefense) {
                
    $this->xdefense $xdefense;
            }

            function 
    setXhit($xhit) {
                
    $this->xhit $xhit;
            }

            function 
    setXdodge($xdodge) {
                
    $this->xdodge $xdodge;
            }

            function 
    setProtect($protect) {
                
    $this->protect $protect;
            }

            function 
    setUpgrlevel($upgrlevel) {
                
    $this->upgrlevel $upgrlevel;
            }

            function 
    setUpgrrate($upgrrate) {
                
    $this->upgrrate $upgrrate;
            }


    }
    ?>

  • #2
    Das Komische ist wirklich nur das nicht der erste Wert, etc mitgenommen werden.
    Ich verstehe nicht so recht, was das bedeuten soll.

    Im Zweifel halt immer debuggen.

    - http://phpforum.de/forum/showthread.php?t=216988
    - http://php-de.github.io/#debugging

    Kommentar


    • #3
      Es geht um die beiden Funktionen setSkills und setItems. Bie einem Charakter (habe ich jetzt getestet) bekomme ich genau das richtige Ergebnis. Alles wurde genauso erstellt wie erwartet. Wenn nun jedoch ein Charakter dazu kommt wird die Funktion nicht richtig ausgeführt. ich bekomme beim fetch den booleanwert "false" zurück. Das PID jedoch kommt in der Funktion an wird danach aber scheinbar nicht richtig im fetch weiter verarbeitet, aus welchem Grund auch immer.

      Kommentar


      • #4
        Zeig mal die Methode dbStatement (und was da gegebenenfalls alles noch interessant ist). In der dürfte es klemmen.

        Kommentar


        • #5
          Danke für deine bisherige Hilfe. Ich habe nun den Fehler selbst herausfinden können durch debuggen etc. Es lag daran das ich Schleifen sozusagen falsch verwendet habe. Ich habe nun alles etwas ausgelagert durch andere Schleifenkonstrukte und nun wurden alle Daten genauso wie ich Sie benötige erstellt.

          Kommentar

          Lädt...
          X