谁能解释我在哪里做错了什么?

时间:2018-07-20 03:58:32

标签: php mysql

当我运行此代码时,它显示解析错误。谁能帮我这个?

 $servername = "localhost";    
$username = "root";      
$password = "";      
$dbname = "form";    

 // Create connection      
$conn = new mysqli($servername, $username,$password, $dbname);          
// Check connection      
if ($conn->connect_error) {
     die("Connection failed: " .$conn->connect_error);      
}  
 SELECT * FROM my_db;    
 $conn->close();

1 个答案:

答案 0 :(得分:1)

您应该使用php标记并删除那些“>”,还应该使用mysqli_query从mysql查询数据

<?php
$servername = "localhost";    
$username = "root";      
$password = "";      
$dbname = "form";    

 // Create connection      
$conn = new mysqli($servername, $username,$password, $dbname);          
// Check connection      
if ($conn->connect_error) {
    die("Connection failed: " .$conn->connect_error);      
}  
$query = mysqli_query($conn,"SELECT * FROM my_db");    
$conn->close();
?>