store mysqli_query result in session

前端 未结 3 1804
轮回少年
轮回少年 2021-01-24 13:10

I want to store the result of a MySQLi query as a session variable so that I can reuse it without executing the query again. I don\'t want to execute the same query on every pag

3条回答
  •  -上瘾入骨i
    2021-01-24 13:41

    Use like this:

    $result = $connection->query("select something from table");
    $_SESSION['session-name'] = $result->fetch_assoc();
    

    OR

    $sql = `select something from table`;
    $result = mysqli_query($sql);
    $_SESSION['session name'] = mysqli_fetch_assoc($result);
    

提交回复
热议问题