0

I have some PHP that is returning an object to a variable:

                $db = new Db(); 
                $db->db_connect(); 
                $testSelectQuery = $db->db_select('SELECT * FROM test');
                //$dbValue = $testSelectQuery[0]->testcol;
                $test = $testSelectQuery[0];
                FB::log($test);

Here is the output of $test:

Object {idtest: "1", testcol: "from db"}

Now when I try to echo one of the columns:

echo $test->testcol

I get an error:

Notice: Trying to get property of non-object

It was just defined as an object in the output. What am I doing wrong and how do I fix it?

Edit: vardump($test) results in: array(2) { ["idtest"]=> string(1) "1" ["testcol"]=> string(7) "from db" }

David Tunnell
  • 7,252
  • 20
  • 66
  • 124

1 Answers1

1

It looks like $test is an associative array

Access it like this:

echo $test['testcol'];
meda
  • 45,103
  • 14
  • 92
  • 122