mysql获取assoc错误

时间:2016-05-29 20:20:38

标签: php mysql mysqli

我正在尝试将数据库连接到php并且我继续收到错误,“mysql_fetch_assoc()期望参数1为mysql_result,第37行给出布尔值”

谁能告诉我有什么问题?谢谢!

这是我的代码:

 <?php
    $dbhost = "localhost";
    $dbuser = "widget_cms";
    $dbpass = "blah123";
    $dbdatabase = "widget_corp";
    $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbdatabase);


    if(mysqli_connect_errno()) {
    die("Database connection failed: " .
        mysqli_connect_error() .
            " (" . mysqli_connect_errno() . ")"
       );
     }  
    ?>

     <?php
    $query = "INSERT INTO subjects (menu_name, position, visible) VALUES           ('database', 9, 0)" ;
    $result = mysqli_query($connection, $query);
    if (!$result) {
        die("database query failed");
    }
    ?>



    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">

   <html lang="en">
     <head>
      <title>databaseConn</title>
     </head>
     <body>

         <ul>
         <?php   while ($row = mysqli_fetch_assoc($result)) {
             //output data from each row
             ?>
             <li><?php echo $row["menu_name"] . " (" . $row["id"] . ")"; ?>      </li>;
       <?php
        }
       ?> 
    </ul>

     <?php 

     mysqli_free_result($result); 

    ?>   

     </body>
    </html>



    <?php mysqli_close($connection); ?>

0 个答案:

没有答案