Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8931713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:10:15+00:00 2026-06-15T09:10:15+00:00

class Group extends dbConnection { //Class for group, for ex. employe and employers. public

  • 0
class Group extends dbConnection { //Class for group, for ex. employe and employers.
    public $name;  // Name of group
    public $pdo;

    public function __construct ($name, dbConnection $pdo) {
    $this->pdo = $database->pdo;
    }

    public function getGroupList() {  
        try //                       FAULTY LINE BELOW \/\/\/\/\/\/\/
        {
          $pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //to catch exceptions

          $stmt = $pdo -> query('SELECT id, Name, Skills FROM '.$this->name); //sql query with group name
          $list = $stmt->fetchAll(PDO::FETCH_NUM); //fetch statement into array
          $stmt -> closeCursor();
          unset($stmt);
          return var_dump($list); //gives pure data
        }
        catch(PDOException $e) 
        {
          return 'There was some error: ' . $e->getMessage();
        }
    }

}

And dbConnect class:

  class dbConnection {
    public $pdo;
    public function __construct () {
        $this->dbConnect();
    }
    public function dbConnect () {
        if((count($_POST) == 6)&&($_GET['a'] == "connect")) {
            $host = $_POST['host'];
            $port = $_POST['port'];
            $username = $_POST['username'];
            $password = $_POST['password'];
            $database = $_POST['database']; 
            try{
                    $pdo = new PDO('mysql:host='.$host.';dbname='.$database.';port='.$port, $username, $password );
                    echo 'Connection successful!';
                    return $pdo;
            }
            catch(PDOException $e){
                    echo 'Error: ' . $e->getMessage();
            }   
        }
    }
}

And execution:

$conn = new dbConnection;
$workers = new Group("workers", $conn);
$workers->getGroupList();

After: “Connection successful” I get error:

Fatal error: Call to a member function setAttribute() on a non-object on line 14

I think that class Group just doesnt get $pdo from dbConnection. I don’t know what I’m doing wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:10:16+00:00Added an answer on June 15, 2026 at 9:10 am

    Change (in dbConnect class)

    $pdo = new PDO('mysql:host='.$host.';dbname='.$database.';port='.$port, $username, $password );
    

    To

    $this->pdo = new PDO('mysql:host='.$host.';dbname='.$database.';port='.$port, $username, $password );
    

    Also change following

    public function __construct ($name, $database) {
      $this->pdo = $database->pdo;
    }
    

    Also In Group class, use $this->pdo instead of $pdo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class dbConnection { public $pdo; public function __construct() { $this->dbConnect(); } public function dbConnect()
class Mage_Sales_Model_Entity_Order_Collection extends Mage_Eav_Model_Entity_Collection_Abstract { protected function _construct() { $this->_init('sales/order'); } public function addItemCountExpr()
I 've the following custom adapter public class GroupAdapter extends ArrayAdapter<Group> { private ArrayList<Group>
I have a Collection Form class MyCollectionForm extends sfForm { public function configure() {
I'm using CakePHP 2. This is my controller. class GroupsController extends AppController { public
public class WordDisplay extends Activity { private int level; private int group; private int
I have this class which creates a grid: class GridPane extends JPanel{ public GridPane(int
I have this 2 classes: @Entity public class Student extends User { ... @ManyToMany(mappedBy
Simple class public class Group { public Int16 ID { get; private set; }
i have these two models public class Group { [Key] public int GroupID {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.