使用mysqli使用php连接数据库

It's not working. The code i used is

    <?php
        $conn=mysqli_connect('127.0.0.1','root','');
        if(!$conn)
        {
            echo "Connection Not Established";
        }
        if(!mysqli_select_db($conn,'lpractice'))
        {
            echo "Database Not Found!";
        }
        $res=mysqli_query($conn,"select * from signup");
        echo "<table>";
            while($row= mysql_fetch_array($res))
            {
                echo "<tr>";
                echo "<td>" . $row['name'] . "</td>";
                echo "<td>" . $row['email'] . "</td>";
                echo "<td>" . $row['age'] . "</td>";
                echo "<td>" . $row['sex'] . "</td>";
                echo "</tr>"

            }
        echo "</table>";
    ?>

And the output coming is

"; while($row= mysql_fetch_array($res)) { echo ""; echo "" . $row['name'] . ""; echo "" . $row['email'] . ""; echo "" . $row['age'] . ""; echo "" . $row['sex'] . ""; echo "" } echo ""; ?>

mysqli_fetch_array not mysql_fetch_array and you're missing a ; after your echo "</tr>"

I think the fundamental problem is not related to mysql. If your output starts after the <table>-tag it looks like your code has not been run by the php interpreter. This happens, for example, when you access the php file directly with your browser.

The usual setup in order to use php is a webserver. There are several solutions you can use. For example, there is xampp which is an easy to use webserver for your own computer for testing and development. Depending on your OS there might are better solutions (such as pre-configured packages on linux or mac).

//Try this

<?php
#create connection
$host_name = "127.0.0.1";
$username = "root";
$password = "";
$database_name = "lpractice";
$connection = mysqli_connect("$host_name","$username","$password","$database_name");

#check connection
if(mysqli_connect_error()){
    echo "Connection Not Established. " .mysqli_connect_error();
    }
$query = "SELECT * FROM signup";
$result = $connection->query($query);
if ($result->num_rows > 0) {
  //echo table header
    echo"
      <table>
        <thead>
           <tr>
             <th>Name</th>
             <th>Email</th>
             <th>Age</th>
             <th>Sex</th>
           </tr>
        </thead>
      ";
while($row = $result->fetch_assoc()) {
// output data of each row
  echo"<tbody>";
    echo"<tr>";
      echo "<td>" . $row['name'] . "</td>";
      echo "<td>" . $row['email'] . "</td>";
      echo "<td>" . $row['age'] . "</td>";
      echo "<td>" . $row['sex'] . "</td>";
    echo"</tr>";
  echo"</tbody>";
echo"</table>";
  }
} else {
    echo "No records found.";
}
$connection->close();
?>