in reply to DBI insert: Need to store results in a MySQL-database (not in a file)
However, if you have to do more work on this database or perhaps you need to write more scripts to extract data or manipulate data, then it is a good investment of your time to look into something like DBIx::Class].
Yes, it takes some learning and it takes some time to set-up the classes for your database, especially if you want to have the relational part right, but once you have done that, using this database becomes a breeze.
Believe me I speak from experience: before I used DBIx::Class I had to write every time I needed to write a new script for that database, again and again very similar code (connecting to the database, writing SQL, setting up the loops to select, insert, delete, ...). Now all these chores just become standard methods of your class.
Adding a next record, could become as simple as:
my $new_school = $schema->resultset('Schools')->create({ location => 1, name => 'mySchool', type => 'HighSchool', adress => 'Paris Champs Ellysees 1', description => 'Ecole Superieur', });
Searching for a record is equally simple:
Once found, you could extract the fields like this:my $rs = $schema->resultset('Schools')->search({name => 'mySchool'});
Updating the record? Even easier!my $school = $rs->first; print $school->adress;
$school->adress('New address of the school'); $school->update;
BTW: for your problem, try adding some or die $dbh->errstr; code to your do statements. You will then be able to see what went wrong.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: DBI insert: Need to store results in a MySQL-database (not in a file)
by morgon (Priest) on Oct 16, 2010 at 13:24 UTC | |
|
Re^2: DBI insert: Need to store results in a MySQL-database (not in a file)
by Perlbeginner1 (Scribe) on Oct 16, 2010 at 16:39 UTC |