Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^8: Relational table with perl DBI

by Neighbour (Friar)
on Mar 13, 2013 at 15:01 UTC ( #1023220=note: print w/ replies, xml ) Need Help??


in reply to Re^7: Relational table with perl DBI
in thread Relational table with perl DBI

That was what @{$hr_output}{@fields} was supposed to catch....it gives you the values of the hash in the order of @fields.
You don't have to follow the exact same order as the fields are defined in the table, but you will have to follow the same order you specified in the INSERT-query, which is why I used @fields a lot at that point.
Also, it seems I made a slight mistake for the last_insert_id-select. It should be<br? my $sth_select_last_insert_id = $dbh->prepare( qq( SELECT LAST_INSERT_ID() )); (Note the added ()).
The other errors are all a result of this. First the query fails (syntax error), which results in an undef result.
But when executing it (at my $article_id = ($dbh->selectcol_arrayref($sth_select_last_insert_id))->[0]; I immediately dereference it. But undef is not an arrayref, so that won't do (and perl complains about that).
Then when trying to insert the undef (which is NULL when stored in a database) in the article_event_index table, an error occurs, which leaves $inserted_records containing undef. When comparing that to a value, perl warns (but proceeds anyway) about that.


Comment on Re^8: Relational table with perl DBI
Select or Download Code
Re^9: Relational table with perl DBI
by M15U (Acolyte) on Mar 14, 2013 at 09:39 UTC
      What does your event-table look like? It seems there is no column named event (even though your original post showed there should be).
      Once again, the insert query fails, $inserted_records becomes undef which doesn't quite compare to a number.

        Well it looks like this :

        $create_query = qq{ create table event( id_event int(10) auto_increment NOT NULL, event MEDIUMTEXT COLLATE utf8_general_ci, primary key (id_event) ) }; $dbh->do($create_query);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023220]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-07-26 13:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (177 votes), past polls