?
Solved

OCIParse / OCIExecute > Multiple sign on's to ORCL?

Posted on 2006-11-29
8
Medium Priority
?
374 Views
Last Modified: 2013-12-12
The PHP script below is having to sign on to the ORCL database every time it runs a query.  The sign on process takes several seconds each time causing the script execution time to run into minutes when it should be seconds.  How do I change this PHP script so that I only have to sign on to the database once?

$conn = OCILogon('username', 'password', 'database_name');
$query1 = "SELECT customer_id FROM table"
$run_query1=OCIParse($conn, $query1);
OCIExecute($run_query1);
while (OCIFetchInto($run_query1, $loop1, OCI_ASSOC)) {
     $query2 = "SELECT count(monkeys),count(bananas) FROM table WHERE customer_id =".$loop1['customer_id'];
     $run_query2=OCIParse($conn, $query2);
     OCIExecute($run_query2);
     while (OCIFetchInto($run_query2, $loop2, OCI_ASSOC)) {
          echo "The customer with Customer ID ".$loop1['customer_id']." has ".$loop2['monkeys']." monkeys and ".$loop2['bananas']." bananas";
     }
}
0
Comment
Question by:Geoff Millikan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 29

Expert Comment

by:TeRReF
ID: 18039135
So, even though you create a connection handle ($conn) you still need to sign on every time? That's weird indeed.
Are you sure
$conn = OCILogon('username', 'password', 'database_name');
is only used once and that it's not in a loop?
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18039210
If this is not the problem, you might want to have a look at your php.ini and look for this directive:
oci8.max_persistent

If you set it to -1 it means there is no limit to the amount of persistent connections...
0
 

Author Comment

by:Geoff Millikan
ID: 18041514
Yes, I'm sure the $conn is not looped.  Good thought.

The more I think about this, I'm wondering if the the sign on actually takes place only in the "$conn" statement?  In otherwords, it only connects once and the reference to "$conn" in the OCIParse function only names the established connection to use?  That would make sense but would be nice to confirm it.  If this is true, then the issue is slow queries, not slow sign on.
 
I tried using "oci_pconnect" but do not see any performance gain.  oci8.max_persistent is set to -1 according to phpinfo().

http://us2.php.net/manual/en/function.ociparse.php

If you can confirm that the sign on only happens once, even though the OCIParse references the connection multiple times, then I'll assign you the points.
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

Author Comment

by:Geoff Millikan
ID: 18042369
FYI - I made two connections like this:

$conn1 = OCILogon('username', 'password', 'database_name');
$conn2 = oci_pconnect('username', 'password', 'database_name');

and then I ran the same query under each connection to see which one was faster.  The script run under OCILogon was faster by about 30%.

The amount of time to run both the $conn1 and $conn2 statements was 0.077306 seconds.
0
 
LVL 3

Expert Comment

by:nishayr
ID: 18042777
If you are looking for a significant performance boost, you might try using bind variables...

Thanks,
Nish
0
 
LVL 29

Accepted Solution

by:
TeRReF earned 2000 total points
ID: 18043587
> The script run under OCILogon was faster by about 30%.
That might be a bit deceiving. If you run the same queries twice after one another, they are probably cached. That would explain the 30% increase in peformance.

Anyway, it looks like the queries themselves are slow. Your current setup selects customer ids from all customers and then you query the DB for each customer id. why don't you change that and drop the first query and adjust the second query like so:
$query2 = "SELECT customer_id, count(monkeys),count(bananas) FROM table GROUP BY customer_id;

And then use a while loop from that result set to print the data...
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question