【发布时间】:2013-11-05 04:35:10
【问题描述】:
我一直在尝试让这个功能工作,因为它是我在线商店的会话获取器。它在 oci_bind_by_name 行上不断出错。我想知道为什么会出现这种情况以及解决此问题的可能方法。
function getSessionID($customerID)
{
global $conn;
$query = "SELECT SESSIONID FROM \"StrSession\" WHERE EMAIL = ':cid'";
$sessInfo = oci_parse($conn, $query);
oci_bind_by_name($sessInfo, ":cid", $customerID, 64);
oci_execute($sessInfo);
$row = oci_fetch_array($sessInfo);
if ($row)
return $row["SESSIONID"];
else
return null;
}
这就是我记录会话的方式:
function logSession($customerID)
{
global $conn;
// Is the customer already logged in? If so, log them out then log back in again.
if (isLoggedIn($customerID))
unlogSession($customerID);
$sessionID = session_id();
$bindVars = array(
array("varname" => "sessionID", "bindname" => ":sid", "length" => 64),
array("varname" => "customerID", "bindname" => ":cid", "length" => 64)
);
// Insert a new row into the session table with the session ID and customer ID
$query = oci_parse($conn, "INSERT INTO \"StrSession\" VALUES(':sid', ':cid')");
foreach ($bindVars as $field)
oci_bind_by_name($query, $field["bindname"], ${$field["varname"]}, $field["length"]);
if (DEBUG) echo "Query: $query\n";
oci_execute($query);
}
最后这是检查登录的方式:
function checkLogin($username, $pass)
{
global $conn;
$passhash = md5($pass);
$query = "SELECT \"EMAIL\" FROM \"StrCustomer\""
. " WHERE \"USERNAME\" = '$username' AND \"PASSWORD\" = '$passhash'";
$loginInfo = oci_parse($conn, $query);
oci_execute($loginInfo);
$row = oci_fetch_array($loginInfo);
if ($row)
return $row["EMAIL"];
else
return null;
}
【问题讨论】:
-
“不断出错”?请具体告诉我们您看到了什么错误。
-
当用户尝试登录时,他们不会被重定向到产品目录,而是看到:ORA-01036 oci_bind_by_name 非法变量/编号
-
这里的表名和占位符都不需要引号。
"INSERT INTO \"StrSession\" VALUES(':sid', ':cid')"); -
嗯,试过了。没用。
标签: php oracle oracle-call-interface