简体   繁体   中英

Cannot use object of type PDOException as array

i'm currently finishing my website and all the stuff works just fine but i keep getting a error. It don't break anything but it's annoying to see. I have been trying alot of stuff but i need some new eyes on this problem :/

Error

PHP Fatal error: Cannot use object of type PDOException as array in /home/thecodin/public_html/memberlist.php on line 114

Code

Line 113: foreach($MemberList as $MemberListEach) {
Line 114: $MemberGroup = $MemberListEach['Group'];
Line 115: $MemberListGroup = $Class_Users->group_info($MemberGroup);

Database Structure

http://gyazo.com/785f780e6b62df6136087070d7c69c65

Member List Class

public function Member_List($offset, $max)
{
    try
    {

        // Run Query - Member List
        $member_list = $this->db->prepare("SELECT * FROM `Users` ORDER BY `Group` DESC LIMIT ".$offset.",".$max."");
        $member_list->execute();

        $member_list_fetch = $member_list->fetchAll();

        return $member_list_fetch;

    } catch(PDOException $e) {

        return array("ERROR", $e);

    }   
}

Group Info Class

public function group_info($id)
{
    try
    {
        // Run Query - Group Info
        $group_info = $this->db->prepare("SELECT * FROM `Groups` WHERE `GID`=:id");
        $group_info->bindParam(':id', $id);
        $group_info->execute();
        $group_info_rows = $group_info->fetch();
        return $group_info_rows;
    } catch(PDOException $e) {
            return array("ERROR", $e);
    }   
}
"/home/thecodin/public_html/memberlist.php on line 114"

line 114 - $MemberListEach['Group']; /* this is array use... */ $MemberListEach['Group']; /* this is array use... */

try dumping object with var_dump

Problem Solved.

I just had to change the return to a string insted of an array in the PDOException like Loz Cherone said.

I hope i'm done this right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM