CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Databases in Perl

 



tallest1
Deleted

Jun 19, 2000, 12:09 AM

Post #1 of 7 (1393 views)
Databases in Perl Can't Post

I think I've outgrown the use of flat-file databases in my scripts and now I'm considering moving to DBM or mySQL databases. I hear that DBM databases are supported on most servers and I also hear that SQL is pretty powerful. Please give me a bit of insight on this.

Plus, can someone give me some links or references on how to create Perl scripts that use DBM and/or mySQL databases?

Thanks in advance


tallest1
Deleted

Jun 18, 2000, 10:02 PM

Post #2 of 7 (1393 views)
Re: Databases in Perl [In reply to] Can't Post

DBI looks *very* interesting. Correct me if I'm wrong but is it merely an interface that translates generic commands into Oracle or SQL commands as long as the server has the driver?

P.S. I'll get that book you mentioned. thanks.


Kanji
User

Jun 19, 2000, 4:08 AM

Post #3 of 7 (1393 views)
Re: Databases in Perl [In reply to] Can't Post

DBM are very hash like and ideal if you have relatively simple db needs, but are hitting performance issues with flat-files.

Relational databases (RDBMS) like MySQL, Access, Oracle, etc. bring a whole new level of possibilities, and is somewhat akin to a hash of arrays (rows of columns), but where you can -- using SQL -- extract data based on arbritrarily complex attributes ("show me everything about everyone" to "give me the names and email addresses of all the people older than 18, whose middle initial is T, have signed up for our spam lists, and spent more than $60 with us in the past").

Both are (usually) very speedy compared to flat-file dbs if your flat-file has grown beyond all reason.

For more info on accessing DBMs, see the DB_File module.

For more info on accessing RDBMSs, see the most excellent DBI and DBD::* modules and DBI webpage.

I also -- and very heartily -- recommend O'Reilly's Programming the Perl DBI, which covers both. ($19.50 at bookpool.com!)


Kanji
User

Jun 19, 2000, 11:47 AM

Post #4 of 7 (1393 views)
Re: Databases in Perl [In reply to] Can't Post

It's more of an abstraction layer for a consistent programming interface.

If you don't do anything too obscure then -- theoretically anyway -- you could just change the connection string ("DSN")in your script and have it all work.

Occassionaly, it's just a matter of tweaking the SQL a tad (like HTML, third-parties have a tendency of extending the spec).

In fact, the only DBI script I've come accross that needed more than fiddling with the DSN or SQL was one of my own (!) that used the ultra groovy DBD::RAM (converts flat files, CSVs, XML, MP3 tags, and more into a DBI/SQL-malleable form), so I threw up my hands and subclassed the module to make another driver so that I didn't have to mangle my scripts to keep them portable!


tallest1
Deleted

Jun 20, 2000, 1:34 PM

Post #5 of 7 (1393 views)
Re: Databases in Perl [In reply to] Can't Post

Well, I got the book today (I would've gotten it from bookpool.com but I was too anxious to learn this stuff ;D )

However, I have 2 more questions for you:

1) Would you still recommend using DBI if I were making a script that would have absolutely no requirements except for a cgi-bin? I want to reach as large an audience as possible even if I must sacrifice speed/efficiency a bit.

2) My script is currently based on a flat file DB which MUST be read from the most to least recent rows. Is it possible to continue doing that with a RDBMS?
...or to rephrase, can I sort a table by the order each row was created and then process the 10 most recent or least recent rows one at a time?

Thanks Again


Kanji
User

Jun 20, 2000, 3:44 PM

Post #6 of 7 (1393 views)
Re: Databases in Perl [In reply to] Can't Post

 <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">quote:</font><HR>1) Would you still recommend using DBI if I were making a script that would have absolutely no requirements except for a cgi-bin?<HR></BLOCKQUOTE>

No. DBI is not part of the standard perl distribution, so using it would require anybody using your script to install DBI if they don't already.

On a side note ...

It could very well be RDBMS is overkill for your application. The same could be said if you limit yourself to a DBM solution. It's possible you haven't outgrown flat-files (the only truly portable format) at all, but are just using them inefficiently.

Without knowing what you're trying to do and sample datasets, it's impossible to say whether its more sane to breakdown and require the use of non-standard modules.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">quote:</font><HR>...or to rephrase, can I sort a table by the order each row was created and then process the 10 most recent or least recent rows one at a time?<HR></BLOCKQUOTE>

Yes, SQL is great for that sort of stuff. Smile

Something like SELECT * FROM table ORDER BY date DESC LIMIT 10 ( select all columns from table, sort them by date in descending order, and only give me the first 10 ).


tallest1
Deleted

Jun 20, 2000, 8:34 PM

Post #7 of 7 (1393 views)
Re: Databases in Perl [In reply to] Can't Post

I think I'll use a DBM database for now and make a mySQL add-on later.
Thanks for all of your help

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives