[英]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.
它会在oci_bind_by_name行上不断出错。 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)");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.