Hey all,<br><br>Sorry, I thought you were interested in some leasure time reading. The DBI book is nice for that. If what you're really after is something like a ref card, the SYNOPSIS of 'perldoc DBI' is probably all you need.<br>
<br>If what you're really after is cheap scripts and your data set isn't huge, the easiest way is:<br><br> my $rows = $dbh->selectall_arrayref( $query, undef, @values );<br><br>No prepare, bind or execute needed. <br>
<br>
If you're ever interested in what's under the hood, the DBI source is actually quiet readable. As for Class::DBI vs DBIx::Class, I won't rehash the flamewar here. Saying that, going straight DBI vs ORM should really depend on what you're doing. When you're mostly doing CRUD and accessing the same tables over and over again, then ORM is definately the goer. But if you're mostly doing custom queries and reporting and never repeating yourself, I would lean more to straight SQL.<br>
<br>Alfie<br><br><div class="gmail_quote">On Thu, Jul 16, 2009 at 5:57 PM, Tim Evans <span dir="ltr"><<a href="mailto:tim.evans@sputnikagency.com">tim.evans@sputnikagency.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I would add to sam's list ...<br>
<br>
$dbh->{mysql_enable_utf8} or die "couldn't init mysql_enable_utf8";<br>
<br>
And as long as the db is set up to support utf8<br>
<br>
$dbh->do("SET character_set_database=utf8");<br>
$dbh->do("SET character_set_server=utf8");<br>
$dbh->do("SET names 'utf8'");<br>
etc.....<br>
<div><div></div><div class="h5"><br>
<br>
On 16/07/09 5:38 PM, "Sam Watkins" <<a href="mailto:sam@nipl.net">sam@nipl.net</a>> wrote:<br>
<br>
>> I want a handy 'desk' reference with<br>
>><br>
>> a) Lots of examples<br>
>> b) Easy to read and complete reference material<br>
>><br>
>> The reason is that I can't hold the details in my head (because I do<br>
>> not DBI regularly) , but I need to keep knocking off dirty that little<br>
>> scripts that run sql queries. I figure the easiest way for that is SQL<br>
>> via DBI rather than an abstraction module.<br>
><br>
> Here is a little "handy desk reference" for you, covering all of DBI<br>
> that you should use. It is shorter than the manpage or a book ;)<br>
><br>
> my $dbh =<br>
> DBI->connect("DBI:mysql:database=$database;host=$hostname;port=$port",<br>
> $username, $password);<br>
> my $sth = $dbh->prepare("SELECT foo, bar FROM baz WHERE foo = ? AND bar<br>
> = ?");<br>
> $sth->execute("foovalue", $barvalue);<br>
> while (my $row = $sth->fetchrow_arrayref) {<br>
> my ($foo, $bar) = @$row;<br>
> print "$foo $bar\n";<br>
> }<br>
> $sth->finish;<br>
><br>
><br>
> You should rarely need to use anything other than the above from DBI.<br>
> keep it simple!<br>
><br>
> I highly recommend using the "bind values" stuff with the ?s in the SQL<br>
> and corresponding parameters to execute. DBI will quote and escape<br>
> values for you correctly so you don't need to worry about SQL injection<br>
> attacks, etc.<br>
><br>
> DBI has umpteen different fetch methods, your life will be easier if you<br>
> just use one of them.<br>
><br>
> regards,<br>
><br>
> Sam<br>
> _______________________________________________<br>
> Melbourne-pm mailing list<br>
> <a href="mailto:Melbourne-pm@pm.org">Melbourne-pm@pm.org</a><br>
> <a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/listinfo/melbourne-pm</a><br>
<br>
_______________________________________________<br>
Melbourne-pm mailing list<br>
<a href="mailto:Melbourne-pm@pm.org">Melbourne-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/listinfo/melbourne-pm</a><br>
</div></div></blockquote></div><br>