gpt4 book ai didi

PHP 数据库查询没有及时完成?

转载 作者:行者123 更新时间:2023-11-30 23:08:16 25 4
gpt4 key购买 nike

我有一个 php 函数,它在页面加载时检查数据库,以查看是否存在可能正在恢复 session 的用户的 session 。如果数据库中不存在任何内容,我们将在流程的“第 1 步”启动它们。但是,如果他们确实有一个他们要返回的事件 session ,我们会得到他们离开的当前步数。这是我的代码:

<?php   
//Start the session we will use to track the activity.
session_start();

//Get the session ID from a previous session if it exists; if not, create one.
$sessionID = $_GET['session'];
$sessionID = ($sessionID ? $sessionID : session_id());

//Define some vars
$mainPage = 'wizard';
require_once('includes/header.php');

//Lets see if we can retrieve an active session for the user.
$objDB = new DB;
$retrieveSession = $objDB->setStoredProc('shadowFetchUserSession')
-> setParam("sessionID", $sessionID)
-> setParam("empID", $empID)
-> execStoredProc()
-> parseXML();

//Do we have a session already?
if($retrieveSession->sessionData){

//This doesnt seem to get the variable in time before the rest of the code fires.
$currentStep = $retrieveSession->sessionData->currentStep;

}else{

//Since we didnt get a step number from the session, lets start at 1.
$currentStep = 1;

//Lets add the session to the database now that we have the sessionID and the current step.
$objDB = new DB;
$makeSession = $objDB->setStoredProc('shadowCreateSession')
-> setParam("sessionID", $sessionID)
-> setParam("empID", $empID)
-> setParam("currentStep", $currentStep)
-> execStoredProc();
}
?>

如果你看一下这个语句

 if($retrieveSession->sessionData){

$currentStep 变量似乎没有在下面代码的其他部分执行之前设置。

有什么明显的我遗漏的东西吗?

最佳答案

这就像你在错误的地方使用 If Else Endif 终止符一样简单吗?

session_start();

//Get the session ID from a previous session if it exists; if not, create one.
$sessionID = $_GET['session'];
$sessionID = ($sessionID ? $sessionID : session_id());

//Define some vars
$mainPage = 'wizard';
require_once('includes/header.php');

//Lets see if we can retrieve an active session for the user.
$objDB = new DB;
$retrieveSession = $objDB->setStoredProc('shadowFetchUserSession')
-> setParam("sessionID", $sessionID)
-> setParam("empID", $empID)
-> execStoredProc()
-> parseXML();

//Do we have a session already?
if($retrieveSession->sessionData){

//This doesnt seem to get the variable in time before the rest of the code fires.
$currentStep = $retrieveSession->sessionData->currentStep;
} else {

//Since we didnt get a step number from the session, lets start at 1.
$currentStep = 1;
}

//Lets add the session to the database now that we have the sessionID and the current step.
$objDB = new DB;
$makeSession = $objDB->setStoredProc('shadowCreateSession')
-> setParam("sessionID", $sessionID)
-> setParam("empID", $empID)
-> setParam("currentStep", $currentStep)
-> execStoredProc();

?>

如果是这样,那么适当的代码缩进可能有助于您在未来发现问题。

关于PHP 数据库查询没有及时完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20910723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com