How to insert stored data from database in an empty array


I am trying to store the rows of data from the database into an empty array. I want to make use of the pdo object as well but I am stuck and don’t understand how to do this.
Thanks in advance.
Here is my php code:

function db_connect() {
  try {
    $servername = DBHOST;
    $databasename = DBNAME;
    $user = DBUSER;
    $password = DBPASS;

    $pdo = new PDO("mysql:host=$servername;dbname=$databasename",$user,$password);
    $pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $pdo;
  catch (PDOException $e)

// Handle form submission
function handle_form_submission() {
  global $pdo;

    $email = $_POST['email'];
    $mood = $_POST['mood'];
    $comments = $_POST['comment']; 
    $date = date('Y-m-d');

    $stmt = $pdo->prepare("INSERT INTO comments (email,mood,commentText,date) VALUES(:email,:mood,:commentText,:date)");


// Get all comments from database and store in $comments which is an array
function get_comments() {
  global $pdo;
  global $comments;

   $sql = $pdo->query("SELECT * FROM comments ORDER BY ID DESC");
   /*while($comments = $sql->fetch()){
     echo $comments['date']."<b />".$comments['mood']."<br />".$comments['email'];





Look at the fetch all method


Ok. I will try that.
Thank You