echo SELECT QUERY mysqli

时间:2016-10-09 11:07:25

标签: php mysql mysqli phpmyadmin

嘿,这是我的代码我不能执行回声" ok"不显示。我该怎么办呢。

 <?php

   $username = "root";
   $password = "";
   $db = "db2";

   // Create connection

   $conn = mysqli_connect("localhost", $username, $password, $db);

   if (!@$conn) {
    die ("Unable to Connect!");
   }
   else {
       echo "Connected!";
   }

   $sql = "SELECT 'food', 'calorie' FROM 'food' ORDER BY 'id'";
   $query = mysqli_query($conn, $sql);
    if ($query) { 
   echo "ok";   
    }
   ?>

1 个答案:

答案 0 :(得分:-2)

<?php

 $username = "root";
 $password = "";
 $db = "db2";

// Create connection

  $conn = mysqli_connect("localhost", $username, $password, $db);

 if (!@$conn) {
  die ("Unable to Connect!");
  }
 else {
   echo "Connected!";
}

 $sql = "SELECT food, calorie FROM food ORDER BY id";
 $query = mysqli_query($conn, $sql);
  if ($query) { 
  echo "ok";   
  }
  ?>