如何显示sqli数据库

时间:2017-09-18 14:52:01

标签: php mysqli

我需要能够显示我的数据库的内容但我不知道如何使用sqli这样做,任何提供的帮助将不胜感激

<?php


ini_set("display_errors",1);
error_reporting(E_ALL);


$servername = "server";
$username = "username";
$password = "password";
$dbname = "sql1702520";


 // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);

我尝试使用下面的mysql查询从数据库中提取数据,但是我被告知不可能使用mysql和sqli

/*
 $result = mysql_query("SELECT * FROM sql1702520 ");
*/


    $conn->close(); 
?>

显示数据库的Html

<html>

 <table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
  <thead>
    <tr>
      <th>id</th>
      <th>Name</th>
      <th>image</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
  <?php

尝试使用它来显示表数据,但是mysql需要这样做

  while( $row1 = mysqli_fetch_assoc( $result ) ){
    foreach ($row1 as $row){
?>
    <tr>
      <td><?php $row['id'] ?></td>
      <td><?php $row['hname'] ?></td>
      <td><?php $row['himage'] ?></td>
      <td><?php $row['hdesc'] ?></td> 
    </tr>
<?php
    }
  }
?>
  </tbody>
</table>
 <?php mysql_close($connector); ?>
</body>


  </html>

1 个答案:

答案 0 :(得分:-1)

假设你的表名(看起来与你的数据库名称有些相似)对于mysqli你必须使用mysqli_query函数来发送你的查询。

$result = mysql_query($conn,"SELECT * FROM sql1702520 ");
你的循环

mysqli_fetch_assoc

$row = mysqli_fetch_assoc($result);

你可以放弃for-each循环。 while循环就足够了。

获取进一步的帮助,错误信息会有所帮助。