$sql = "SELECT srcid FROM sensors LIMIT 3"; $query = $dbh->query($sql); $ids = $query->fetchAll(\PDO::FETCH_COLUMN); // http://blog.encodez.com/blog/using-pdofetchall-examples-with-codes-and-output-results