Strange problem connecting php to oracle db

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith E. Sauvant

    Strange problem connecting php to oracle db


    A behaviour we don't understand:

    +++
    $user = 'xxx';
    $password = 'xxx';
    $database = 'xxx.xxx';

    $query = 'SELECT 1 FROM DUAL';
    $link = OCIlogon($user, $password, $database);

    //$parse = OCIParse($link, $query);
    unset($link);

    $link = OCIlogon($user, $password, $database);
    $parse = OCIParse($link, $query);
    +++
    -> "... is not a valid oci8 connection resource"

    Everything works fine if the first line with $parse is not
    commented out. Everything also works fine if we do not
    unset $link.

    This behaviour occurs with ocilogon(), not with
    either ociplogon() or ocinlogon().

    Tested with PHP 4.3.11 on Linux, Apache 1.3.33 and Apache
    1.3.34, OCI PECL extension 1.1.1, Oracle 10.2.01 and
    10.1.0.3.

    Best regards
    Keith
  • Mladen Gogala

    #2
    Re: Strange problem connecting php to oracle db

    On Mon, 20 Feb 2006 13:16:46 +0100, Keith E. Sauvant wrote:
    [color=blue]
    >
    > A behaviour we don't understand:[/color]

    Who is "we"?
    [color=blue]
    >
    > +++
    > $user = 'xxx';
    > $password = 'xxx';
    > $database = 'xxx.xxx';
    >
    > $query = 'SELECT 1 FROM DUAL';
    > $link = OCIlogon($user, $password, $database);
    >
    > //$parse = OCIParse($link, $query);
    > unset($link);[/color]

    Why would do that? Unset will call the destructor and will
    log you out of the database? Are you trying to log in for
    each SQL statement?


    [color=blue]
    >
    > $link = OCIlogon($user, $password, $database);
    > $parse = OCIParse($link, $query);
    > +++
    > -> "... is not a valid oci8 connection resource"
    >
    > Everything works fine if the first line with $parse is not
    > commented out. Everything also works fine if we do not
    > unset $link.
    >
    > This behaviour occurs with ocilogon(), not with
    > either ociplogon() or ocinlogon().
    >
    > Tested with PHP 4.3.11 on Linux, Apache 1.3.33 and Apache
    > 1.3.34, OCI PECL extension 1.1.1, Oracle 10.2.01 and
    > 10.1.0.3.
    >
    > Best regards
    > Keith[/color]


    I would have written that like this:

    $link = OCIlogon($user, $password, $database);
    if (!$link) {
    $err=oci_error( );
    die("General Protection Fault:$err<br>\ n");
    }
    $handle1 = OCIParse($link, $query1);
    $handle2 = OCIParse($link, $query2);

    /* Note that checking for errors makes no sense as oracle
    does error checking only when it attempts to execute
    the cursor. */

    oci_execute($ha ndle1);
    $err=oci_error( $link);
    if ($err) die("General Protection Fault:$err<br>\ n");

    oci_execute($ha ndle2);
    $err=oci_error( $link);
    if ($err) die("General Protection Fault:$err<br>\ n");

    Note that error checking is necessary after each statement as neither OCI8
    nor PHP4 support exceptions. I wholeheartedly recommend switching to PHP5
    as it is stable enough for production and makes the life of poor
    programmer much, much easier.


    --


    Comment

    • Keith E. Sauvant

      #3
      Re: Strange problem connecting php to oracle db

      >> A behaviour we don't understand:[color=blue]
      > Who is "we"?[/color]

      That is me and my colleagues ;-)
      [color=blue]
      > Why would do that? Unset will call the destructor and will
      > log you out of the database? Are you trying to log in for
      > each SQL statement?[/color]

      I do not want to do that. That where just some lines of code to
      reproduce my problem.
      [color=blue]
      > I would have written that like this: ...[/color]

      You are absolutely right. But besides that: Can you explain what happens
      in my example?

      Best regards
      Keith

      Comment

      • Mladen Gogala

        #4
        Re: Strange problem connecting php to oracle db

        On Mon, 20 Feb 2006 21:55:39 +0100, Keith E. Sauvant wrote:
        [color=blue]
        > You are absolutely right. But besides that: Can you explain what happens
        > in my example?[/color]

        You have destructor mess up something and the new connect is not
        able to go through. It would be much easier to debug you code
        snippet if there was an entry from the error_log file or oci_error
        result. This is just guesswork, but that is all that I can tell,
        based on what you gave me.

        --


        Comment

        Working...