|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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. |
|
#2
|
||||
|
||||
|
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.
|
|
#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. |
|
#4
|
||||
|
||||
|
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?
|
|
#5
|
||||
|
||||
|
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. |
|
#6
|
||||
|
||||
|
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.
|
|
#7
|
||||
|
||||
|
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.
|
|
#8
|
||||
|
||||
|
RE: odbc_close() not working...
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > odbc_close() not working... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|