store mysqli_query result in session

前端 未结 3 1801
轮回少年
轮回少年 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条回答
  •  迷失自我
    2021-01-24 13:57

    If you want to store the data not only for one client, but serverside I would recommend you to look at how to build a in-memory server side cache in php?. Some frameworks have this already built in.

    Otherwise use one of the mysqli API methods like http://php.net/manual/de/mysqli-result.fetch-assoc.php, this should return you an array not an object.

    mysqli_query() returns an object which you can not store into session (there is a method for converting an object to an array, but I would not recommend you to store the whole object) http://php.net/manual/de/function.get-object-vars.php

提交回复
热议问题