【发布时间】:2014-07-21 20:46:58
【问题描述】:
我想在一个文件中执行查询,将其存储在会话变量中,然后在另一个文件中访问结果。
文件1.php:
//This is the file I have executed my sql statement in
//I have already done session_start(); and initialized $conn
$query = //my query. I know it is working because I have tested it elsewhere, so I
// don't believe it is the problem
$_SESSION['query2'] = mysqli_query($conn, $query)
文件2.php:
//This is the file I want to access my query results in.
//I have already done session_start(); and initialized $conn
$tempArray = $_SESSION['query2'];
if (isset($tempArray)) {
$row = mysqli_fetch_array($tempArray, MYSQL_NUM);
if ($row == null) {
echo "<h1> error </h1>"; //This line gets executed
} else {
echo "<h1> works! </h1>";
}
} else {
echo "<h1> array not set </h1>";
}
关于我做错了什么有什么想法吗?或者,还有其他方法可以完成我在这里尝试做的事情吗?
【问题讨论】:
标签: php mysql mysqli session-variables