简体   繁体   中英

PHP OCI error oci_bind_by_name

I have been trying to get this function to work, for context it is meant to be a session fetcher for my online store. It keeps erroring out on the oci_bind_by_name line. I was wondering why this is the case and possible solutions to this problem.

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;
}

This is how I am logging the sessions:

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);
}

Finally this is how logins are checked:

    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;
}

Do not put single quotes around your bind variable. Simply remove them. This is what you would want to do for your select query:

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

And for your insert query:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM