Solved

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

Posted on 2006-11-29
8
373 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 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

724 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