Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Nov 21st, 2007, 5:52 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,885
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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 exist

Therefore the global scope does not get passed into a file that is imported.

Your solution?
Sane is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:47 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC