难道php的文档里写的不够清楚吗?
http://cn.php.net/manual/zh/function.oci-fetch-array.php

解决方案 »

  1.   

    呵呵,给你看我们用的一个函数:
    getMatrix:
    function GetMatrix($stmt)
    {
    $ncols=OCINumCols($stmt);
    $column_name=array();
    for($i=1;$i<=$ncols;$i++)
    {
    $column_name[$i-1]=OCIColumnName($stmt,$i);
    }
    $i=0;
    $arr2=array();
    while(OCIFetchInto($stmt,&$arr,OCI_RETURN_LOBS))
    {
    for($j=0;$j<$ncols;$j++)
    {
    $arr2[$column_name[$j]]=$arr[$j];
    }
    $matrix[$i]=$arr2;
    $i++;
    }
    $this->EnumPointer=0;
    OCIFreeStatement($stmt);
    return $matrix;
    }
      

  2.   

    TO screend(流浪小子):
      我用的也是php4, 你的这种方法也想过, 有没有不用自己转换, 可以在返回的结果集里直接用字段名字取值的方法?(设置项等等)
      

  3.   

    呵呵,我们常用的函数:
     function GetMatrixBindVer($strSQL,$BindVerName,$Color="blue")//miller yuan for bind variable
     {
    $debugstatus=$_SESSION["debugstatus"];
    if($debugstatus=="on"){?>
    <font color=<?=$Color?>> <A href="/webex/database.php?strSQL=<?=urlencode($strSQL)?>" target="new"> <b>debug:</b></A><?=htmlspecialchars($strSQL)?><br></font>
    <?}
    $conn=OCIConnect();

    //Begin a transaction
    //In anytime,set full time format
    $stmt=OCIParse($conn,"ALTER SESSION SET NLS_DATE_FORMAT = 'MM/DD/YYYY HH24:MI:SS'");
    OCIExecute($stmt);

    //Parse and run SQL
    $stmt=OCIParse($conn,$strSQL);

        $BindVerNameLength = sizeof($BindVerName);  
    for ($i=1;$i<=$BindVerNameLength;$i++) 
    {                         
    OCIBindByName($stmt,$BindVerName[$i-1][0], &$BindVerName[$i-1][1], strlen($BindVerName[$i-1][1]));
    }  
    $rtn = OCIExecute($stmt);
    if(!$rtn)

    print "This sql statement have errors:".$strSQL."<br>";

    //Get column name to array
    $ncols=OCINumCols($stmt);  

    $column_name=array();
    for($i=1;$i<=$ncols;$i++)
    {
    $column_name[$i-1]=OCIColumnName($stmt,$i);
    }
    //Record set
    $i=0;
    $arr2=array();
    while(OCIFetchInto($stmt,&$arr,OCI_RETURN_LOBS))
    {
    for($j=0;$j<$ncols;$j++)
    {
    $arr2[$column_name[$j]]=$arr[$j];
    }
    $rs[$i]=$arr2;
    $i++;
    }
    OCIFreeStatement($stmt);

    //Commit a transaction
    OCICommit($conn);
    OCIDisconnect($conn);
    return $rs;
     }

    } // end of !define("__OCICONNECT_INC__")