PDO get value

Is there any way to write an efficient code better than this.


try{
                $sql = "SELECT * FROM device.monitor WHERE del_stat IS NULL AND id = ?";
                $q = connection::$db->prepare($sql);
                $q -> bindValue(1, $id, PDO::PARAM_INT);
                $q ->execute();

                $row = $q->rowCount();
                        if ($row == 0) {
                            echo 'no records found.';
                        }else{

                           while ($row = $q->fetch(PDO::FETCH_ASSOC))
                            {
                              $mon = $row['mon_brand'];
                              $ay= $row['id'];
                              $return[] = array($mon, $ay);

                            }
                                                   }
        }catch (Exception $e) {
            print "Error!:" . $e->getMessage();
        }

because everytime I call the values I just do the following:


foreach ($view as $test)
{
  $id = $test[1];
  $brand = $test[0];
}

I wonder if there is another way of doing it like calling just automatically call the id and it will show its value.
Thank you in advance.

I’m not completely sure to understand what you’re asking?
You pass the id in the query, so it should return only one row? What do you need the while loop for?
And I don’t see any connection between the two pieces of code you posted?

If you have an associative array (like your first example), you can use [fphp]extract[/fphp]