PHP OCI错误oci_bind_by_name

时间:2013-11-05 04:35:10

标签: php oracle oci

我一直试图让这个功能起作用,对于上下文来说,它意味着我的在线商店的会话提取器。它在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;
}

1 个答案:

答案 0 :(得分:-1)

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

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

对于您的插入查询:

$query = oci_parse($conn, "INSERT INTO \"StrSession\" VALUES(:sid, :cid)");