There was a node tonight I came across that mentioned DBD::DBM in regards to a more rebust system than just DB_File and SDBM_File but more usable for those who don't know MySQL/SQL. The node is Creating HTML tables.

I have very little experience with MySQL or any database other than the ones that came with my Perl package, so bare with me.

Using the example code from CPAN (see below) resulted in three files being created. test.pag, test.dir and test.lck. Then I created a new table and that created three more files prepended with "test1".

There must be some way to have the set of tabular data not each be their own separate files. If I have 100 tables, I can't handle 300 files in one directory just for the database to work.

From the code you can see I tried adding the extension ".db" as per the manual but that still resulted in the creation of three files per table.

When using my $dbh=DBI->connect('dbi:DBM:type=DB_File'); file instead, it still created three files but one of them didn't have an extension. So the question is, is there a way for this to create one or maybe two files total for the entire database or is this what to expect from DBD::DBM?

Second question is seems more of an SQL question but when you SELECT something from the table such as:

SELECT phone FROM user WHERE user_name < 'Fred';
To store the results, you could use:
my $var = SELECT phone FROM user WHERE user_name < 'Fred';
Right? Again, I have never really gotten into MySQL but this little DBI looks like it could come in handy so I don't have to continue split()ing all my values from my hashes.

Thanks for your help.

use DBI; my $dbh = DBI->connect('dbi:DBM:ext=.db'); $dbh->{RaiseError} = 1; for my $sql( split /;\n+/," CREATE TABLE test ( user_name TEXT, phone TEXT ); INSERT INTO test VALUES ('Fred Bloggs','233-7777'); INSERT INTO test VALUES ('Sanjay Patel','777-3333'); INSERT INTO test VALUES ('Junk','xxx-xxxx'); DELETE FROM test WHERE user_name = 'Junk'; UPDATE test SET phone = '999-4444' WHERE user_name = 'Sanjay Pate +l'; SELECT * FROM test "){ my $sth = $dbh->prepare($sql); $sth->execute; $sth->dump_results if $sth->{NUM_OF_FIELDS}; } $dbh->disconnect;


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

In reply to DBD::DBM file creation by sulfericacid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.