You need to write a helper function to create the DB connection if it doesn't 
already exist and then return it if it does.  The reason you're hitting this is 
because every time you request a page, you get a random child process from 
Apache.  You don't know which one you're going to get, and it's unlikely you'll 
get the same one over and over again.  Once you create the DB handle the first 
time in the global scope, it will remain in that Apache child, but you may get 
a different child next time.

Damon


On Oct 28, 2010, at 10:45 PM, Clif Flynt wrote:

> Hi,
>  I think I'm missing something simple.
> 
>  I may be getting bit by threads.
> 
>  The system I'm building is a database backed web application. 
> Nothing particularly complex.
> 
>  I open a connection to the database using tdbc - this creates
> a new command that I put in the global scope as '::db1'.
> 
>  A few minutes later, I hit a web page, and the command is gone.
> 
>  It's simple enough to re-create it, but I'm getting bored with
> adding the 'is it still here' check to my code.
> 
>  Is there a way to open a persistent link?  Or am I getting caught by
> a new thread being assigned to a session and the new thread has never
> heard of any ::db1 command.
> 
>  Maybe I should drop the tdbc idea and move to dio...  My primary 
> reason for using tdbc is that I'm not convinced that we won't be 
> switching backends before we get out of prototype mode and tdbc seemed
> like the simplest way to be server-neutral.
> 
>  Thanks for insights,
>  Clif
> 
> -- 
> ... Clif Flynt ... http://www.cwflynt.com ... [email protected] ...
> .. Tcl/Tk: A Developer's Guide (2nd edition) - Morgan Kauffman ..
> .. 17'th Annual Tcl/Tk Conference:  2010,   Oak Brook, IL  USA ..
> .............  http://www.tcl.tk/community/tcl2010/  ............
> 
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to