当我使用oci_fetch_array并且计数i得到22(我认为这意味着它得到两行)这是错误的它应该是11(11是列数)和 当我使用oci_fetch_row时,我得到1是正确的。 谁能告诉我为什么会这样?
$sql = "SELECT * FROM USERS WHERE USERNAME= :uname AND PWORD = :pword";
$stmt = oci_parse($c, $sql);
$uname=$_POST['uname'];
$pword=$_POST['pword'];
oci_bind_by_name($stmt, ":uname",$uname);
oci_bind_by_name($stmt, ":pword",$pword);
oci_execute($stmt);
$res = oci_fetch_array($stmt);
$res2 = oci_fetch_row($stmt);
$num = count($res);
$num2 = count($res2);
echo $num . "<br/>";
echo $num2 . "<br/>";
答案 0 :(得分:2)
根据docs,oci_fetch_array的工作方式与mysql_fetch_array类似,因此您必须遍历数组。
这意味着,您只将第一行保存在oci_fetch_array中,而应该这样做
$sql = "SELECT * FROM USERS WHERE USERNAME= :uname AND PWORD = :pword";
$stmt = oci_parse($c, $sql);
$uname=$_POST['uname'];
$pword=$_POST['pword'];
oci_bind_by_name($stmt, ":uname",$uname);
oci_bind_by_name($stmt, ":pword",$pword);
oci_execute($stmt);
$data = array();
while($res = oci_fetch_array($stmt))
{
$data[] = $res;
}
$num = count($data);
echo $num . "<br/>";
答案 1 :(得分:1)
oci_ *库与php中的mysql_ *并不太相似。
获取数组将返回类似于此
的内容Array(0 => "some_key" => "some_value")
fetch assoc将返回
的位置Array("some_key" => "some_value")
我记不起来了,但我确信这是你问题的根源。