0

我一直试图让这个功能工作,因为上下文它是我在线商店的会话获取器。它在 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;
}
4

1 回答 1

-1

不要在绑定变量周围加上单引号。只需删除它们。这是您想要为您的选择查询做的事情:

$query = "SELECT SESSIONID FROM \"StrSession\" WHERE EMAIL = :cid";

对于您的插入查询:

$query = oci_parse($conn, "INSERT INTO \"StrSession\" VALUES(:sid, :cid)");
于 2015-12-29T14:47:28.607 回答