简体   繁体   中英

No longer able to connect to mysql using PHP

I keep getting the following error:

Fatal error: Call to a member function fetch_array() on boolean in C:\\xampp\\htdocs\\DeletePlayerSOLN\\DeletePlayerExample_SOLN\\index.php on line 10

Any idea what the problem is? I searched previous threads and tried to identify the problem for the past few hours. I'm new to PHP.

I'm using Xampp + Mysql.

MySQL connection: 127.0.0.1 3306 root Default Schema: test

I'm connected through port 443,4433 through Xampp. So I try to connect through /localhost:443/folder..filename..

Connection:

    //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);
?>

Index page:

<?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>

Line 10 is "while($row = $results->fetch_array())"

It is likely that $mysqli->query() is not producing a proper object due to an error. Try replacing

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

with

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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