繁体   English   中英

警告:mysqli_query() 期望参数 1 为 mysqli,给出的值为 null?

[英]Warning: mysqli_query() expects parameter 1 to be mysqli, null given in?

我正在为我的高中年度项目制作一个网站。 php文件中出现以下错误:

警告:mysqli_query() 期望参数 1 为 mysqli,在第 89 行的 /host/home1/jbts/html/db/Plot-log.php 中给出空值

这是php源码。

<?php
$link=mysqli_connect("localhost","xxxx","xxxxxxxxx","jbts");
if (!$link)
{ echo "MySQL error : "; echo mysqli_connect_error(); exit(); }
mysqli_set_charset($link,"utf8");
$sql = "select * from Plot-log";
$result = mysqli_query($link, $sql);
?>

我在这样的 html 文件中使用。

<tr>
    <?  while($row=mysqli_query($con, $sql)){ ?>
        <tr> 
          <td> <?=$row[0]?></td> 
          <td> <?=$row[1]?></td>
          <td>  <?=$row[2]?></td>                                           
</tr>
    <?
    }
    ?>

要输出数据,您需要使用其中一种获取方法 - 在本例中为mysqli_fetch_assoc

<?php
    /* be consistent with the name of the db connection object - $link */

    $link=mysqli_connect("localhost","xxxx","xxxxxxxxx","jbts");
    if( !$link ) exit( "MySQL error : ". mysqli_connect_error() );


    mysqli_set_charset( $link, "utf8" );
    $sql = "select * from `Plot-log`";

    $result = mysqli_query( $link, $sql );

?>

下面的名称需要更改为表中列的实际名称。

<?php
    if( $result ){
        while( $rs=mysqli_fetch_assoc( $result ) ){
            echo "
            <tr>
                <td>{$rs['FIELD_NAME_1']}</td>
                <td>{$rs['FIELD_NAME_2']}</td>
                <td>{$rs['FIELD_NAME_3']}</td>
            </tr>";
        }
    }
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM