0

I can't collect the results of my query in this function :

<?php
function getBestScore()
{
    require_once ('connection.php');

    $idJoueur = session_id();

    if ($stmt = $conn->prepare('SELECT bestScore FROM Player WHERE ID = ?'))
    {
        $stmt->bind_param('i', $idJoueur);
        $stmt->execute();
        $result = $stmt->get_result();

        $data = $result->fetch_assoc();

        $bestScore = $data;

        if (!(empty($bestScore)))
        {
            header("Location: ../index.php");
        }

        return $bestScore;
    }
    else
    {
        $error = $conn->errno . ' ' . $conn->error;
        echo $error;
    }

}

My connection works, I tried fetch_assoc(), store_result() but I failed every time.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Louis
  • 44
  • 1
  • 5

1 Answers1

-2

If you want to select data then try the following

if ($stmt = $conn->prepare('SELECT bestScore FROM Player WHERE ID = ?')) {
    $stmt->bind_param('i',$idJoueur);
    $stmt->execute();

    /* bind result variables */
    $stmt->bind_result($result);

    /* fetch value */
    $stmt->fetch();

    if (!(empty($result))) {
        header("Location: ../index.php");
    }

    return $result;
}

Hope this helps.