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

Re: MySQL count with DBI

by smitz (Chaplain)
on May 09, 2003 at 12:05 UTC ( [id://256833]=note: print w/replies, xml ) Need Help??


in reply to MySQL count with DBI

Yeah I had an idea once, a combination Hat and Shoe, but the backers dropped out and I
lost EVERYTHING. Anyway, does this answer your non-question?
#!perl -w use strict; use DBI; my $dbh = DBI->connect('DBI:mysql:my_database', 'my_username', 'my_pas +sword') or die "Couldn't open database: $DBI::errstr; stopped"; # Prepare the SQL query for execution my $sth = $dbh->prepare(<<SQL) or die "Couldn't prepare statement: $DB +I::errstr; stopped"; SELECT COUNT(*) FROM table SQL # Execute the query $sth->execute() or die "Couldn't execute statement: $DBI::errstr; stop +ped"; #print result my ($count) = $sth->fetchrow_array(); print "Found $count results\n";
Smitz

Yeah I copied and pasted from stephens excellent Reading from a database. Sorry, stephen

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found