how do I print the result of a query to the screen.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • orfiyus
    New Member
    • Jul 2007
    • 36

    how do I print the result of a query to the screen.

    I am trying to print the result of the query to the screen. For example Im looking to count the number of times REC appears in my db which is 3 times. So I could say select count(*).... which would output the number 3. When I put this into my code I only get 1. I get 1 no matter what happens. I looked up ociexecute and its 1 for success or 0 for fail. How would I accomplish this?Every example I see is too confusing.

    Code:
    //$db_conn = <the database connection info. >
    $query = "select count(*) from test_table";
    $parsed = ociparse($db_conn, $query);
    $succ = ociexecute($parsed);
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Don't despair. I can't see anything wrong with this so far.
    You just haven't gone far enough.

    The value returned by ociparse is a resource identifier.
    ociexecute($par sed) executes the statement.
    Note the resource identifier is passed in the function
    Now you need to unravel the result.
    You will need
    Code:
    oci_fetch_array ($parsed) 
    //or 
    oci_fetch_assoc ($parsed).
    Your query will only return a count which should be the first array element
    Code:
    $query = "select count(*) from test_table";
    So to see this figure use
    [PHP]$result = oci_fetch_array ($parsed);
    $count = $result[0];
    echo 'Count '.$count;[/PHP]I think this last bit is right. Apologies if not.

    Comment

    • orfiyus
      New Member
      • Jul 2007
      • 36

      #3
      yo code green

      Thanks alot man this helped me out alot. The only reason I needed to see the output on the screen was for debugging purposes. This really helped Ive been trying to get this output for at least 2 days. I have been looking all over google and I never found a clear answer. Anyway thanks for taking the time to look at this for me.

      Peace

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        No problem. I have never used the oci functions and I was curious to know whether they were similar to mysql,mssql and ODBC functions

        Comment

        Working...