Php 将MySQL数据添加到引导表

Php 将MySQL数据添加到引导表,php,mysql,Php,Mysql,所以,我有一些基本的表代码从引导更新的列标题,我想 <table class="table"> <thead class="thead-dark"> <tr> <th scope="col">#ID</th> <th scope="col">Unit Name</th> <

所以,我有一些基本的表代码从引导更新的列标题,我想

    <table class="table">
  <thead class="thead-dark">
    <tr>
      <th scope="col">#ID</th>
      <th scope="col">Unit Name</th>
      <th scope="col">Assignment Name</th>
      <th scope="col">Due Date</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>

<table class="table">
  <thead class="thead-light">
    <tr>
      <th scope="col">#</th>
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
我已经设置了连接,我只是不知道如何连接表和数据库

<?php 

// this code will only execute after the submit button is clicked
if (isset($_POST['submit'])) {
    
    // include the config file that we created before
    require "config.php"; 
    
    // this is called a try/catch statement 
    try {
        // FIRST: Connect to the database
        $connection = new PDO($dsn, $username, $password, $options);
        
        // SECOND: Create the SQL 
        $sql = "SELECT * FROM works";
        
        
        // THIRD: Prepare the SQL
        $statement = $connection->prepare($sql);
        $statement->execute();
        
        // FOURTH: Put it into a $result object that we can access in the page
        $result = $statement->fetchAll();

    } catch(PDOException $error) {
        // if there is an error, tell us what it is
        echo $sql . "<br>" . $error->getMessage();
    }   
}
?>

使用这个概念

<?php

$mysqli = new mysqli("localhost","my_user","my_password","my_db");

// Check connection
if ($mysqli -> connect_errno) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
  exit();
}

// Perform query
if ($result = $mysqli -> query("SELECT * FROM Persons")) {
    $arr_result= mysqli_fetch_array($result);
}

$mysqli -> close();

echo '
<table class="table">
    <thead class="thead-dark">
        <tr>
              <th scope="col">#ID</th>
              <th scope="col">Unit Name</th>
              <th scope="col">Assignment Name</th>
              <th scope="col">Due Date</th>
        </tr>
    </thead>
    <tbody>
';
while($arr_result){
    echo '
     <tr>
      <th scope="row">1</th>
      <td>'.$arr_result["FirstName"].'</td>
      <td>'.$arr_result["LastName"].'</td>
      <td>'.$arr_result["mdo"].'</td>
    </tr>';
    $arr_result= mysqli_fetch_array($result);
}

echo '
    </tbody>
</table>';
?>


这已经关闭,它显示了列标题,但仍然没有连接。我已经编辑了我原来的帖子
<?php

$mysqli = new mysqli("localhost","my_user","my_password","my_db");

// Check connection
if ($mysqli -> connect_errno) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
  exit();
}

// Perform query
if ($result = $mysqli -> query("SELECT * FROM Persons")) {
    $arr_result= mysqli_fetch_array($result);
}

$mysqli -> close();

echo '
<table class="table">
    <thead class="thead-dark">
        <tr>
              <th scope="col">#ID</th>
              <th scope="col">Unit Name</th>
              <th scope="col">Assignment Name</th>
              <th scope="col">Due Date</th>
        </tr>
    </thead>
    <tbody>
';
while($arr_result){
    echo '
     <tr>
      <th scope="row">1</th>
      <td>'.$arr_result["FirstName"].'</td>
      <td>'.$arr_result["LastName"].'</td>
      <td>'.$arr_result["mdo"].'</td>
    </tr>';
    $arr_result= mysqli_fetch_array($result);
}

echo '
    </tbody>
</table>';
?>