![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programming Guru
![]() |
Avoid Connecting To MySQL Multiple Times
I have a project of .cgi scripts. This is a quick outline of how the files are being mapped together:
index.py
import header
<Display some header HTML>
import mysqllib
<Connect to MySQL and assign the instance to a local variable>
<Display some information via variable mysqllib.db>
import footer
import mysqllib
<Connect to MySQL and assign the instance to a local variable>
<Display some information via variable mysqllib.db>The problem should be apparent: both the main page and the footer connects to MySQL. How can I save time and use the same connection to MySQL? I don't want to connect twice. And I don't want to remap any of the files, because this way makes most sense for how things need to be pieced together. I have tried: Set a global variable in index.py using globals()
"import footer"
In footer.py, access the global variable using globals()
The global variable does not existTherefore the global scope does not get passed into a file that is imported. Your solution? |
|
|
|
|
|
#2 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3
![]() |
Re: Avoid Connecting To MySQL Multiple Times
Is there a way you could have index.py (or an equivalent outermost structure) keep track of the connection and the inner items could query the outer structure for a connection? I haven't used Python much at all, so I don't know if or how that would work out...
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#3 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Re: Avoid Connecting To MySQL Multiple Times
pconnect ('persistent' connect).
Specifics depend on whatever library you happen to be using.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#4 | |
|
Programming Guru
![]() |
Re: Avoid Connecting To MySQL Multiple Times
Quote:
There is no pconnect in the Python MySQL library, and even if there were, I want to avoid even trying to connect a second time. I don't even want to have to include my mysqllib.py wrapper and the MySQLdb module twice. |
|
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
Re: Avoid Connecting To MySQL Multiple Times
Too bad Arevos hasn't been posting lately. I know he'd know the way in a second flat.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Connecting MySQL and PHP | titaniumdecoy | PHP | 10 | Feb 25th, 2008 7:47 PM |
| MySQl simple problem | paulchwd | Other Web Development Languages | 7 | Feb 27th, 2007 10:31 AM |
| Connecting to MySQL through VB6 | wrestlenovi | Visual Basic | 3 | May 25th, 2006 8:06 PM |
| Tutorial - Using MySQL in C# | Darkhack | C# | 12 | Jan 17th, 2006 9:28 AM |
| Simple Perl / MySQL Problem.. pls help! | domquemo | Perl | 0 | Jan 11th, 2006 4:08 AM |