I am using perl, v5.10.1 and DBD::Sybase (version 1.11) and trying to get number of rows returned from queries run against MS SQL Server (version 11)
The code I am using is a working code but we have moved from MySQL to MS SQL Server and the $sth->rows that used to give me number of rows returned by a DB query is now returning -1 for every query.
As far as I could find, $sth->rows should work for DBD::Sybase as well.
Here is the sample code (just to show the behavior):
#!/opt/apps/perl/perl5101/bin/perl use strict; use warnings; use DBI; use CGI; use CGI::Carp qw(fatalsToBrowser); use CGI qw/:standard/; $| = 1; my $db_server = "<hostname>"; my $db_user = "<user_name>"; my $password = '<password>'; my $query = new CGI; print $query->header; my $form_user = "something.like.this.com\\" . $query->param('site_user +'); my $domain_user = param('user') || $form_user; #1 my @userNameString = split /\\+/, $domain_user; #2 my $userName = $userNameString[1]; #3 my $db_action; my $sql; my $sth; my %widget=(); my $logfile = "LogFileName.log"; open(my $fh, ">>", $logfile) or die "Could not open file '$logfile' $! +"; print $fh "Start of script: ". localtime()."\n"; my $dbh = DBI->connect("DBI:Sybase:server=$db_server",$db_user,$passwo +rd) ; die "unable to connect to server $DBI::errstr" unless $dbh; my $sql18 = "SELECT role FROM table_1 WHERE user = ?";#Returns only 1 +row my $sth18 = $dbh->prepare($sql18); $sth18->execute($userName); $dbh->commit; my $rowCount = $sth18->rows; my $role; while (my @row_18 = $sth18->fetchrow_array) { $role = $row_18[0]; } print "<html>\n"; print "<head>\n"; print "</head>\n"; print "<body>\n"; print "<form id=\"form1\" method=\"post\">\n"; print "The role of user \"$userName\" is: $role\n"; print "</br>\n"; print "The number of rows returned is: $rowCount\n"; print "</br>\n"; print "<input type=\"submit\" name=\"submitButton\" value=\"Submit +\" id=\"button1\"/>\n"; print"<input type=\"submit\" name=\"resetButton\" value=\"Reset\" +id=\"button2\"/>\n"; print "</form>\n"; print "</body>\n"; print "</html>\n";
In output I see "The number of rows returned is: -1"
In code I am using $sth->rows at 6 places for 6 different queries and it still gives correct row count on existing code which is for MySQL.
Can you please help me to find out what am I missing here?
In reply to DBD::Sybase $sth->rows returns -1 by Perl300
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |