Solved

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

Posted on 2006-11-29
8
372 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 500 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

738 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