User Control Panel
Advertisements

HELP US, HELP YOU!

fetchrow

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
xiloki
Newbie
Newbie


Joined: 28 Mar 2005
Posts: 12
Location: pa
Reputation: 13.8

PostPosted: Wed Mar 30, 2005 9:13 am    Post subject: Reply with quote

I'm currently writing a bot in perl using net::oscar..

Now I just got done with my host about fixing problems with MySQL4.1 and the current dbd-mysql problem.

Now when I try to retrieve data from my db to insert into my bot I get the error : DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at on_im.pl line 33.
I read some places and they were talking about making sure you use the same quote in your code. I've done that.

Anyone know whats goin on here?
Code:
<br /><br /><br />use DBI;<br />use MySql;<br />use Strict;<br /><br />sub on_im{<br />   my ($aim,$client,$msg,$away) = @_;<br />   <br /><br />  #filter message for html<br />  $msg =~ s/<(.|\n)+?>//g;  <br />  <br />  #print im to cmd window<br />  print "[$client] $msg\n\n";<br />  <br />  #send the typing status to client<br />  $aim->send_typing_status ($client,TYPINGSTATUS_STARTED);<br />  <br />  #sleep for rate limit<br />  sleep(3);<br />  <br />           #connect to db<br />      my $dbh = DBI->connect("DBI:mysql:<tablename>:,<hosthere>",",<namehere>","<passhere>");<br />        <br />      #retrieve clients info from db<br />      my $query = "select id, sn, name, website from users where sn = $client";<br />      my $sth = $dbh->prepare($query);<br />      $sth->execute();<br />      <br />      while (my $user_array = $sth->fetchrow_hashref()) {<br />      print "sn : $user_array->{'sn'}";<br />      <br />      }<br />      $sth->finish();<br />      $dbh->disconnect();<br />  <br />  #do work<br /><br />  <br />     #send im<br />  $aim->send_im($client,$reply);<br />  <br />  #print response to im window<br />  print "[$screenname] $reply\n";<br />  <br />  #stop the typing status<br />  $aim->send_typing_status ($client, TYPINGSTATUS_FINISHED);<br /><br />   <br />}<br />1;<br />
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Wed Mar 30, 2005 3:10 pm    Post subject: Reply with quote

The problem is that your SQL has an error in it. Look at the cpan docs for DBI. It has information on error catching and using place holders. you put $client straight in the SQL which means it won't be qouted, which is why you get the error.

The following code should at least be closer to what you want. Usering placeholders is very important for security so you should learn to alway always always use them. Wink
Code:
<br />     my $query = "select id, sn, name, website from users where sn = ?";<br />     my $sth = $dbh->prepare($query);<br />     $sth->execute($client);<br />

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
xiloki
Newbie
Newbie


Joined: 28 Mar 2005
Posts: 12
Location: pa
Reputation: 13.8

PostPosted: Wed Mar 30, 2005 7:59 pm    Post subject: Reply with quote

QUOTE(eric256 @ Mar 30 2005, 10:10 AM)
The problem is that your SQL has an error in it.  Look at the cpan docs for DBI.  It has information on error catching and using place holders.  you put $client straight in the SQL which means it won't be qouted, which is why you get the error.

The following code should at least be closer to what you want.  Usering placeholders is very important for security so you should learn to alway always always use them. Wink
Code:
<br />     my $query = "select id, sn, name, website from users where sn = ?";<br />     my $sth = $dbh->prepare($query);<br />     $sth->execute($client);<br />

[right][snapback]47361[/snapback][/right]


Ok thanks.
I did that and now I don't get the fetchrow error but it's reply is blank and it makes trillian go boom boom bang error!!! Says that it's crashed and needs to close.

Any ideas?
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Wed Mar 30, 2005 9:14 pm    Post subject: Reply with quote

You caused trillian to crash? That shouldn't have anything to do with your bot, unless your bot is sending some sort of weird information. In the code you showed us you aren't even sending a message to the user so I don't know what to tell you.
_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
xiloki
Newbie
Newbie


Joined: 28 Mar 2005
Posts: 12
Location: pa
Reputation: 13.8

PostPosted: Wed Mar 30, 2005 11:51 pm    Post subject: Reply with quote

Ok i got it going, thanks
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group