By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,570 Members | 1,612 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,570 IT Pros & Developers. It's quick & easy.

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

P: 36
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.

Expand|Select|Wrap|Line Numbers
  1. //$db_conn = <the database connection info. >
  2. $query = "select count(*) from test_table";
  3. $parsed = ociparse($db_conn, $query);
  4. $succ = ociexecute($parsed);
Jul 23 '07 #1
Share this Question
Share on Google+
3 Replies

code green
Expert 100+
P: 1,726
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($parsed) executes the statement.
Note the resource identifier is passed in the function
Now you need to unravel the result.
You will need
Expand|Select|Wrap|Line Numbers
  1. oci_fetch_array ($parsed) 
  2. //or 
  3. oci_fetch_assoc ($parsed).
Your query will only return a count which should be the first array element
Expand|Select|Wrap|Line Numbers
  1. $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.
Jul 23 '07 #2

P: 36
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.

Jul 23 '07 #3

code green
Expert 100+
P: 1,726
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
Jul 27 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.