Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old March 23rd, 2004, 12:11 AM
icandothat's Avatar
icandothat icandothat is offline
Moderator
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 1,556 icandothat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 3 h 46 m 51 sec
Reputation Power: 3
odbc_close() not working...

This is making me crazy. I have programmed a fairly large database app. In PHP, (about 5K lines of code). It all seems to work well but once or twice a day I get an SQL error "System Resources Exceeded". I don't have any queries that return thousands of results (well ok I have a couple, but only thousands, not tens of thousands of results, and these work just fine). So, I am assuming it is a memory leak in my code. I put "or die" after some of my odbc_close() statements and they are failing. Up until now I just assumed they worked. So far I have tried putting odbc_free_result() statmements in before the odbc_close() but it dosn't seem to help. Anyone have any Idea of what I might try next?

Included is a snip of code...
<?

$db = odbc_connect("phonebook","","")
or die("no connection");
$query = "SELECT P.FIRST_NAME,P.LAST_NAME FROM PHONEBOOK P ORDER BY P.LAST_NAME";

$queryResult = odbc_exec($db,$query)
or die("query didn't work");


//Blah blah... some code to display results
//etc...


odbc_free_result($queryResult)
or die("Unable to free result");
odbc_close($db)
or die("Unable to close db ");
}
?>

When I run this I get "Unable to close db" from my or die.

Reply With Quote
  #2  
Old March 23rd, 2004, 09:14 PM
icandothat's Avatar
icandothat icandothat is offline
Moderator
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 1,556 icandothat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 3 h 46 m 51 sec
Reputation Power: 3
RE: odbc_close() not working...

OK an update. I turned off persistant connections in the php.ini file. This did nothing to help. I also realized that odbc_close does not return anything and that you probably can't use an or die on it. Fine So This is what I did to test it. I opened a connection just like above. I executed a query, I freed the result after I got it, then ran odbc_close. Then, I executed a query on the connection that was supposed to be closed and bam I got a result. The connection was still open. ????? please anyone help. BTW My back end is an Access database.

Reply With Quote
  #3  
Old March 23rd, 2004, 10:33 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: odbc_close() not working...

I've never used Access as a back-end to any of my PHP apps, so maybe this doesn't make any sense, but it does for other databases.

Why did you turn persistent connections off? Your database is going to do a lot less work if you are not constantly opening and closing connections. It's nice to close connections you aren't using, but if you are connecting to the same database as the same user for every page in your application, persistant connections make sense.

Does Access have any logging features? If so, turn them on, they might give you an indicator as to where to look for your problem.

Reply With Quote
  #4  
Old March 24th, 2004, 07:58 AM
icandothat's Avatar
icandothat icandothat is offline
Moderator
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 1,556 icandothat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 3 h 46 m 51 sec
Reputation Power: 3
RE: odbc_close() not working...

If persistant connections is on can i open the connection once and thats it? What I mean is ... when the script runs and the page is displayed I don't have to open the connection again the next time the script runs for that user? This is tough to explain. My users will "manage" a database through the front end I wrote, mostly running lookup type queries and some minor editing. Now suppose I have a funtion called "find_user()" and a button to execute the function. Can I just open the connection once when the user logs in ? Or do i still have to open it every time the function is run by the same user. Does that make sense?

Reply With Quote
  #5  
Old March 24th, 2004, 11:22 AM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: odbc_close() not working...

I think there's some confusion by what "open a connection" means ... because there's sort of two.

As far as the database is concerned, you can open a connection and that connection stays open until it timesout or until it is explicitly closed.

As far as PHP is concerned, you open a connection with a function like odbc_connect() and close it with odbc_close(). However, with persistent connections, if PHP sees that a connection is already opened (that uses the same server, user, and password), it reuses that. You still have to call odbc_pconnect() to get the handle and open a connection if there is not one available though.

So, I guess the answer is both yes and no to your question. You don't need to open a new connection for every page from the db's perspective, but you do need to call odbc_pconnect() in each of your PHP pages.

Take a look at the documentation for odbc_connect() and odbc_pconnect(). They might say it more clearly than I have.

Reply With Quote
  #6  
Old March 26th, 2004, 08:00 AM
icandothat's Avatar
icandothat icandothat is offline
Moderator
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 1,556 icandothat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 3 h 46 m 51 sec
Reputation Power: 3
RE: odbc_close() not working...

I read up on pconnect() I'll try that. Thanks for the help. I'll wait till Friday then close the thread.


Reply With Quote
  #7  
Old March 28th, 2004, 07:09 AM
icandothat's Avatar
icandothat icandothat is offline
Moderator
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 1,556 icandothat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 3 h 46 m 51 sec
Reputation Power: 3
RE: odbc_close() not working...

Ok I changed all of my odbc_connect to pconnect. So far so good. I'm gonna close this thread thanks for the help.

Reply With Quote
  #8  
Old March 28th, 2004, 07:09 AM
icandothat's Avatar
icandothat icandothat is offline
Moderator
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 1,556 icandothat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 3 h 46 m 51 sec
Reputation Power: 3
RE: odbc_close() not working...


Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > odbc_close() not working...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway