Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^6: Inserting, update and deleteting a database under conditions

by Nik
on Jan 15, 2008 at 16:00 UTC ( #662492=note: print w/replies, xml ) Need Help??


in reply to Re^5: Inserting, update and deleteting a database under conditions
in thread Inserting, update and deleteting a database under conditions

Well i frgoto 'my'. Except that when iam trying to print @dbfiles it display to me the numder 28, so i guess my statement concernign @dbfiles is also wrong. I was trying to get the data from columns title and body.

how can i write that properly and what logical error do you see?

  • Comment on Re^6: Inserting, update and deleteting a database under conditions

Replies are listed 'Best First'.
Re^7: Inserting, update and deleteting a database under conditions
by apl (Monsignor) on Jan 15, 2008 at 16:14 UTC
    How does $db get initialized? When you do the INSERT, what values should be in place of the question marks you specified?
      Like this:
      #===================================================================== +========== my $db = ( $ENV{'SERVER_NAME'} !~ /varsa/ ) ? DBI->connect('DBI:mysql:orthodox;localhost', 'root', '******' +, {RaiseError=>1}) : DBI->connect('DBI:mysql:skieros_orthodox;www.freegreece.net', + 'skieros_root', '******', {RaiseError=>1}); #===================================================================== +========== my @files = glob "$ENV{'DOCUMENT_ROOT'}/data/text/*.txt"; my @filenames = map {/([^\/]+)\.txt$/} @files; my @dbfiles = $db->do( 'SELECT title, body FROM articles' ); foreach my $filename (@filenames) { unless( grep /^\Q$filename\E$/, @dbfiles ) { open FILE, "<$filename" or die "Cannot open $filename: $!"; my $data = <FILE>; close FILE; unless( grep /^\Q$data\E$/, @dbfiles ) { $db->do('INSERT INTO test (title, body) VALUES (?, ?)', undef +, $filename, $data) } } }
      The content of @dbfiles isnt what i think it is though. What i wanted to return is all table's articles contents.
        1. @dbfiles doesn't contain what I thought
        2. @dbfiles is filled using $dbh->do
        3. I wonder what the return value of $dbh->do is?
        4. I wonder if the DBI documentation mentions the return value of the do method?
        OK, that should tell you why your code returns what it does. To get your code to do what you want, I'd recommend consulting DBI recipes.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://662492]
help
Chatterbox?
[Corion]: Hmmm - Mano Negra or at least Manu Chao seem to put on a good live show. At least the one live CD I have from Manu Chao sounds good ;)
Discipulus feels the same jealousity of the johngg's daughter
[1nickt]: choroba I agree
[choroba]: Playing in a punk rock band for 20 years... my hearing is quite bad
[Corion]: I still have hopes to turn my godson and his two siblings into a punk band ;)
[Corion]: Their older sister just started piano but has been interested in drumming, which she should be able to start with 8 years or so)
[Discipulus]: ah was Kink of Bongo 1992..
[1nickt]: choroba name of band? youtube link? MySpace link?

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-03-24 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (301 votes). Check out past polls.