![]() |
|
|
|
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? |
|
|
|
| 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 |