使用终端连接到Mariadb

I use PHP to send a query to the terminal and I want to receive the table that the database produces. I am new to PHP and having difficulties with the connection of the website and the database that I access from the terminal.

    <?php

    $con = new mysqli('localhost','root','','db');
    $query = "";

    if($con->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } else {
        echo "Connection Successful."
    }

    if($_SERVER["REQUEST_METHOD"] == ["POST"]) {
        $query = test_input($_POST["uni_name"]);
    }

    $prompt = 'select * from students where university like ' . $query . '%';


    $dir = shell_exec("use db");
    if($dir == NULL) {
        $output = shell_exec($prompt);
        echo "test";
    }

    setModal($output);

    function test_input($data) {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
    }

    function setModal($query) {
        echo '<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">Graduate Information</h4>
      </div>
      <div class="modal-body">
      '; 
        echo $query;
        echo '
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>';
    }
?>

The setModal function is to create a Bootstrap modal and display the info I get from the database. My main problem is the connection between the database and the website.

Thanks in advance..