The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
PHP and Python DB
Discuss PHP and Python DB in the Python Programming forum on Dev Shed. PHP and Python DB Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 7th, 2004, 09:48 PM
|
|
Contributing User
|
|
Join Date: Dec 2001
Posts: 52
Time spent in forums: 29 m 44 sec
Reputation Power: 12
|
|
|
PHP and Python DB
I am designing a website for a hobby of mine and part of it is in XML dynamically generated by using PHP to extract the element's appropriate data from a database and then parsing it with an XSLT stylesheet (again w/ PHP). This can be done fairly easily but part of the purpose of the site is to practice web programming. I wanted to learn Python so I am using that to develop a communications script for a different section. While studying the language, I had an idea and wanted to know how viable it is. What if instead of using MySQL for the database, I used a Python dictionary? It may sound silly, but would it be slow, perhaps just plain stupid? I really don't need any of the special functions of a relational database...but should I just stick to MySQL? Thanks.
Ryan Kaskel - MIA
Last edited by ryankask : June 7th, 2004 at 09:50 PM.
Reason: grammar
|

June 7th, 2004, 10:54 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
It would work, all you'd have to do is show PHP how to parse the dictionary from a file and insert it into a hash. Though I dont see the need for it if your just learning it should be fun  . Yes, it might be slower than MySQL; especially with large data sets. Give it a go  .
Mark.
__________________
programming language development: www.netytan.com – Hula
|

June 8th, 2004, 01:41 AM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
|
If you can hold all the data in memory all the time, then using a dictionary will be orders of magnitude faster than using a DB. If you have to save and load it from disk each time then I think it will be faster for small data sets, but the DB will overtake it at some point. You may also have the issue of multiple users trying to access the file at the same time, with the potential for data loss.
There is an alternative. Look at the dbm family of modules in the standard library. These look like dictionaries but are simple databases (not relational, so do not have all the overheads associated with that). I recommend bsddb if your OS supports it, since it can support transactions and multiple simultaneous users.
Dave - The Developer's Coach
|

June 8th, 2004, 11:28 AM
|
|
Contributing User
|
|
Join Date: Dec 2001
Posts: 52
Time spent in forums: 29 m 44 sec
Reputation Power: 12
|
|
|
So the dbm module with a standard Python distribution? I assume my web host (which supports Python) will have this module preinstalled? Thank you, I will look into it.
|

June 8th, 2004, 11:38 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
There are actually a number of dbm modules included with Python. Which ones you have will depend on your playform etc. But there is always at least one available. And you can also use the Pickle module for this kind of thing  . Check out the Python docs for more info...
Have fun,
Mark.
|

June 8th, 2004, 11:39 AM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
Quote: | Originally Posted by ryankask So the dbm module with a standard Python distribution? I assume my web host (which supports Python) will have this module preinstalled? Thank you, I will look into it. |
It is standard but optional, depending on the OS. Most UNIX systems have dbm and/or gdbm. Windows and some UNIX installations have bsddb.
All installations have dumbdbm available, which is a simple implementation in Python, and is meant as a last resort.
If you use anydbm then it will transparently use the best implementation available on that system.
I think only bsddb supports multiple users, so if you are using it in a web app then check with your host to see if it is available (or write a short CGI test script).
Dave - The Developers' Coach
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|