New to OCI - double results?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sonnich

    New to OCI - double results?

    Hello there

    I'm trying to work with the example for OCI... and the $row returns 2
    values, the same twice, but my query only have one... code below.

    Can anyone explain?

    BR
    S


    $query = 'select distinct(someth ing) from a.b';

    $stid = oci_parse($conn X, $query);
    if (!$stid) {
    $e = oci_error($conn X);
    print htmlentities($e['message']);
    exit;
    }

    $r = oci_execute($st id, OCI_DEFAULT);
    if (!$r) {
    $e = oci_error($stid );
    echo htmlentities($e['message']);
    exit;
    }

    print '<table border="1">';
    while ($row = oci_fetch_array ($stid, OCI_RETURN_NULL S))
    {

    print '<tr>';
    print "<td>".(count($ row))."</td>";
    foreach ($row as $item) {
    print '<td>'.$item.' </td>';
    }
    print '</tr>';
    }
    print '</table>';

    oci_close($conn X);

  • Rik

    #2
    Re: New to OCI - double results?

    Sonnich <sonnich.jensen @elektrobit.com wrote:
    Hello there
    >
    I'm trying to work with the example for OCI... and the $row returns 2
    values, the same twice, but my query only have one... code below.
    >
    Can anyone explain?
    >
    while ($row = oci_fetch_array ($stid, OCI_RETURN_NULL S))
    Returns the next row from a query as an associative or numeric array


    "returns an array with both associative and numeric indices."

    So, tell it which one to use either associative:
    oci_fetch_assoc ($stid, OCI_RETURN_NULL S)

    Or numerical:
    oci_fetch_row($ stid, OCI_RETURN_NULL S)

    If you don't need the indexes, the last one seems to be the fastest.
    --
    Rik Wasmus

    Comment

    • Andy Hassall

      #3
      Re: New to OCI - double results?

      On 26 Jan 2007 08:52:57 -0800, "Sonnich" <sonnich.jensen @elektrobit.com wrote:
      >I'm trying to work with the example for OCI... and the $row returns 2
      >values, the same twice, but my query only have one... code below.
      [snip]
      while ($row = oci_fetch_array ($stid, OCI_RETURN_NULL S))
      oci_fetch_array returns the values twice - once with numeric indexes, and
      again with the names of the columns as keys.

      Returns the next row from a query as an associative or numeric array


      The default mode is OCI_BOTH - you don't want that.

      --
      Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
      http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

      Comment

      • Sonnich

        #4
        Re: New to OCI - double results?

        I got this to work using
        while ($row = oci_fetch_row ($stid))

        But not I get another problem, see comment here:

        $stid = oci_parse($conn X, $sql2);
        if (!$stid)
        {
        $e = oci_error($conn X);
        echo htmlentities($e['message'])."<br>";
        }
        else
        {
        $r = oci_execute($st id, OCI_DEFAULT);
        // instead of going ahead, it still gives the error here. How do I
        stop that.
        // the error is correctly catched here anyway, but I'd like to have it
        only. Meaning no default response when the query fails.
        if(!$r)
        {
        $e = oci_error($stid );
        if(strpos($e['message'],"CONNECT BY loop")!==false)
        echo "<font class=\"error\" >Loop error with item:
        $Item[$i]</font><p>";
        else
        echo htmlentities($e['message'])."<br>";
        }
        else
        {



        On Jan 26, 6:52 pm, "Sonnich" <sonnich.jen... @elektrobit.com wrote:
        Hello there
        >
        I'm trying to work with the example for OCI... and the $row returns 2
        values, the same twice, but my query only have one... code below.
        >
        Can anyone explain?
        >
        BR
        S
        >

        Comment

        • Mladen Gogala

          #5
          Re: New to OCI - double results?

          On Mon, 29 Jan 2007 09:03:12 -0800, Sonnich wrote:
          I got this to work using
          while ($row = oci_fetch_row ($stid))
          >
          But not I get another problem, see comment here:
          >
          $stid = oci_parse($conn X, $sql2);
          if (!$stid)
          {
          $e = oci_error($conn X);
          echo htmlentities($e['message'])."<br>";
          }
          else
          {
          $r = oci_execute($st id, OCI_DEFAULT);
          // instead of going ahead, it still gives the error here. How do I
          stop that.
          By using the standard PHP error suppression operator:


          $r = @oci_execute($s tid, OCI_DEFAULT);

          I would advise against doing that, but it is a possibility. OCI does
          so called deferred parse, which means that parse and execute steps are
          bundled into a single step. When your statement fails, it's usually a
          serious situation.



          --

          Comment

          Working...