Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

net::mysql has_selected_record always returns true

by steve_s741 (Initiate)
on Mar 17, 2013 at 12:12 UTC ( [id://1023902]=perlquestion: print w/replies, xml ) Need Help??

steve_s741 has asked for the wisdom of the Perl Monks concerning the following question:

Irrespective of whether the SQL results in records being returned or not, this has_selected_record method of net::mysql always seems to return true. This exact issue has been raised before (http://www.perlmonks.org/?node_id=482863) and there is no sign of a resolution within that thread. This has had me tearing my hair out for days. I've simplified my script down to bare bones and still get the same result. Surely, if anyone out there is using net::mysql, this issue must have been experienced by others. Surely? So, here is the code that I run against the empty 'orders' table in my 'invemtory' database:
use DBI; use Net::MySQL; my $mysql = Net::MySQL->new( hostname => '127.0.0.1:8889', # Default use UNIX socket database => 'inventory', user => 'root', password => 'root' ); $mysql->query(q{select * from orders}); if ($mysql->has_selected_record) { print "found in DB...\n"; }
And the output:
bash-3.2$ perl -T test.pl found in DB...
A lot of people seem to suggest using DBD::mysql instead. I have used DBD::mysql n other platforms but getting it to work on Mac OS-X has proven to be beyond me. I read a post somewhere suggesting to try net::mysql and that's how I ended up in this rabbit hole. Is this module supported or is it a dead end?

Replies are listed 'Best First'.
Re: net::mysql has_selected_record always returns true
by thomas895 (Deacon) on Mar 17, 2013 at 18:23 UTC

    You might still be able to use DBD::mysql.
    First, make sure you install the libmysqlclient libraries and headers. Download them from the MySQL website.
    Then, try to use cpan to install DBD::mysql again.

    HTH

    ~Thomas~ 
    "Excuse me for butting in, but I'm interrupt-driven..."
Re: net::mysql has_selected_record always returns true
by igelkott (Priest) on Mar 17, 2013 at 20:43 UTC
    getting it to work on Mac OS-X

    I agree with thomas895. I got DBD::mysql running on OS X (10.8) in pretty much the same way I'd do for Linux. Installed MySQL for OS X from their website then got DBD::mysql through CPAN (after sudo to root). Didn't have to force or do anything usual.

Re: net::mysql has_selected_record always returns true
by Laurent_R (Canon) on Mar 17, 2013 at 16:41 UTC

    Are you sure that your query isn't returning any record?

      Unless there are possible conditions where a query on an empty table should return a result, then I'm pretty confident. Certainly when I run same query at MySql shell I get nothing back.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found