不再能够使用PHP

时间:2016-03-10 03:34:40

标签: php mysql xampp

我一直收到以下错误:

致命错误:在第10行的C:\ xampp \ htdocs \ DeletePlayerSOLN \ DeletePlayerExample_SOLN \ index.php中调用boolean上的成员函数fetch_array()

知道问题是什么吗?我搜索了以前的线程,并试图找出过去几个小时的问题。我是PHP的新手。

我正在使用Xampp + Mysql。

MySQL连接: 127.0.0.1 3306 根 默认架构:测试

我通过端口443,4433通过Xampp连接。所以我尝试通过/localhost:443/folder..filename ..

连接

连接:     

    //make a database connection object
    $mysqli = new mysqli($server, $user, $pass, $database); 

    //test if there are database connection errors
    if ($mysqli->connect_error) 
        die("Connect Error " . $mysqli->connect_error);
?>

索引页:

<?php
    require "serverCode/connect.php";

    $selectPlayer = "SELECT * FROM player ORDER BY playerLastName, playerFirstName";

    $results = $mysqli->query($selectPlayer);

    $ddlString = "<select name='cboPlayer' size='10'>";

    while($row = $results->fetch_array())
    {
        $ID = $row["playerID"];
        $name = $row["playerLastName"] . ", " . $row["playerFirstName"];
        $ddlString .= "<option value='$ID'>$name</option>";
    }
    $ddlString .= "</select>";
    $mysqli->close();
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
            <title>DELETE Player Page</title>
     </head>

  <body>
  <form name="frmPlayer" action="serverCode/deletePlayer.php" method="get">

        Select a player:<p><?php echo $ddlString;?>
                        <input type="submit" name="btnSubmit"></p>                  
  </form>
  </body>
</html>

第10行是“while($ row = $ results-&gt; fetch_array())”

1 个答案:

答案 0 :(得分:1)

由于错误,$mysqli->query()可能无法生成正确的对象。尝试替换

$results = $mysqli->query($selectPlayer);

$results = $mysqli->query($selectPlayer) or trigger_error($mysqli->error."[$selectPlayer]");