in reply to Perl Mysql Null Recordset

The DBI execute returns the number of rows affected. In the case of a select, it returns the number of rows found. Argh! My bad... jZed caught my mistake. So, something like:

$rs1->execute; if (@{$rs1->fetchrow_array}) { report_error("username_exists"); } else { report_error("username does not exist"); }

You could also have fun with the ternary operator:

$rs1->execute; report_error( (@{$rs1->fetchrow_array) ? "username_exists" : "username + does not exist" );

The ternary operator works by checking the truth of the first part (before the ?) and returning the second part if it is true, else returning the third part.


radiantmatrix
require General::Disclaimer;
Perl is

Replies are listed 'Best First'.
Re^2: Perl Mysql Null Recordset
by jZed (Prior) on Nov 17, 2004 at 22:08 UTC
    No, execute only returns the rows affected with *NON-SELECT* statement handles. From the DBI docs:

    "For SELECT statements, execute simply "starts" the query within the database engine. Use one of the fetch methods to retrieve the data after calling execute. The execute method does not return the number of rows that will be returned by the query (because most databases can't tell in advance), it simply returns a true value."