Gossamer Forum
Home : Products : Links 2.0 : Customization :

help creating second database

Quote Reply
help creating second database
I'm wondering if someone might lend a hand with this. I'm trying to write certain fields (not all) to a second file. Iv'e looked in the db.pl file and it should probably go in the sub add_record section. Preferably, I would like to just have it print out in this format $rec|$rec1|$rec2|etc...

Unfortunately, I don't know enough to get this going. If anyone can offer some assistance, I would really appreciate it. Thank you for any replies.
Quote Reply
Re: [matto] help creating second database In reply to
*bump*

I could really use some help with this, as I'm manually adding them to the second db right now. Any suggestions, even if it's just a guess would be great. Thanks for your help.
Quote Reply
Re: [matto] help creating second database In reply to
Of course, the question is, what are you trying to do? That would be helpful...

Here's an idea, you can change the red parts to suite your needs:

Code:
open (DBNAME, ">>$db_name_db") or &cgierr("Unable to open nameyour file: $db_name_db. Reason: $!");
flock(DBNAME, 2) unless (!$db_use_flock);
print DBNAME "$id|$title|$url|$Desc|$Email|$date\n";
close DBNAME; # automatically removes file lock

Put it in db.pl, in the sub add_record, after this:
Code:
if ($status eq "ok") {
Then you ned to create the empty db file in your data directory. This: DBNAME can be anything, it's a file handle to make the code easier to read. This: db_name_db should correspond to the name of the file you create in the data directory (db_name.db). These: "$id|$title|$url|$Desc|$Email|$date are the fields that will be written to the file. Use these, or create your own after adding them to the admin.pl.

This should help you out, but I don't guarantee it'll work...


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] help creating second database In reply to
Nice...thank you very much PerlFlunkie! I'll give it a shot and let you know how it turns out.
Quote Reply
Re: [matto] help creating second database In reply to
Also, just came across this, might be helpful:

http://www.gossamer-threads.com/...0new%20pages;#167267


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] help creating second database In reply to
I couldn't get your way to work, (it would never write to the file) but it helped me tremendously! I just needed to add a few things - not sure if it's the right way to do it, buy hey it works! Anyway, for anyone else needing this here's what I did - couldn't have done it without your help.

Ok first I added this in the links.cfg file

$db_database_name = "$db_script_path/data/database.db"



Then in the links.def file I added:

$db_file_name2 = $db_database_name;



Then in the db.pl file I added:

open (DBNAME, ">>$db_file_name2") or &cgierr("Unable to open file: database.db. Reason: $!");
flock(DBNAME, 2) unless (!$db_use_flock);
print DBNAME "$in{'ID'}|$in{'Title'}|$in{'OtherFields'}\n";
close DBNAME; # automatically removes file lock



Seems to work! Thanks again for your help, I really appreciate it.