User Control Panel
Advertisements

HELP US, HELP YOU!

MySQL

 
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: Sat Apr 02, 2005 7:19 am    Post subject: Reply with quote

Using MySql I want my bot to take the sn of the person iming it and look it up in my database. I thought I could do it this way. But it says that it can't call the prepare method. I'm guessing because the SQL isn't right. Any Idea's?


Code:
<br />sub on_im{<br />my ($aim,$client,$msg,$away) = @_;<br /><br /><br />      #connect to db<br />      my $dbh = DBI->connect("DBI:mysql:<database>:<host>","<username>","<pass>");<br />      print( "Connected to database\n") if( defined $dbh );<br /><br />      my $sth = $dbh->prepare("SELECT name FROM users where sn = ?");<br />     print( "Query executed properly\n") if( defined $sth );<br /><br />      $sth->execute($client);<br />    <br />      while ( my $hashref = $sth->fetchrow_hashref()) {    <br />  print $hashref->{"name"} . "\n";<br />   }<br />       $sth->finish();<br />       $dbh->disconnect();<br /><br />}<br />1;<br /><br /><br />
Back to top
alienz
Almost An Agent
Almost An Agent


Joined: 22 Mar 2004
Posts: 1436
Location: Mars
Reputation: 55.7

PostPosted: Fri Apr 08, 2005 5:51 am    Post subject: Reply with quote

Posting the actual message would help. From what I can see you have this correct.
_________________
Check out Botworld! A dev resource for things bot.
Downloads, articles, news, fourm and more.
http://botworld.marzopolis.com
Back to top
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Fri Apr 08, 2005 8:16 pm    Post subject: Reply with quote

Yes, it seems correct, but you really do not want to connect and query your database everytime sends you a message. Instead, create a public variable for the connection (or stuff it in the AIM object, whatever you want) and re-use that. Connecting each time will dramatically slow down your bot.
Back to top
alienz
Almost An Agent
Almost An Agent


Joined: 22 Mar 2004
Posts: 1436
Location: Mars
Reputation: 55.7

PostPosted: Sun Apr 10, 2005 4:14 pm    Post subject: Reply with quote

Good point, you should only need to connect once for the life of the bot.
_________________
Check out Botworld! A dev resource for things bot.
Downloads, articles, news, fourm and more.
http://botworld.marzopolis.com
Back to top
thomashp
Member
Member


Joined: 22 Feb 2004
Posts: 121
Location: Richmond, VA
Reputation: 29.3Reputation: 29.3Reputation: 29.3

PostPosted: Mon Apr 11, 2005 3:37 am    Post subject: Reply with quote

QUOTE(xiloki @ Apr 1 2005, 11:19 PM)
Code:
<br />sub on_im{<br />my ($aim,$client,$msg,$away) = @_;<br /><br /><br />      #connect to db<br />      my $dbh = DBI->connect("DBI:mysql:<database>:<host>","<username>","<pass>") or die $dbh->errstr;<br />      print( "Connected to database\n") if( defined $dbh );<br /><br />      my $sth = $dbh->prepare("SELECT name FROM users where sn = ?") or die $dbh->errstr;<br />     print( "Query executed properly\n") if( defined $sth );<br /><br />      $sth->execute($client);<br />    <br />      while ( my $hashref = $sth->fetchrow_hashref()) {    <br />  print $hashref->{"name"} . "\n";<br />   }<br />       $sth->finish();<br />       $dbh->disconnect();<br /><br />}<br />1;<br /><br /><br />

[right][snapback]47458[/snapback][/right]


Try this code. If something is wrong, it should die and tell you the error when it does. Make sure you are running your bot from a command prompt and not just double clicking it, so you can see the error when the script closes. If you still can't see the problem, post here exactly what it says when the script dies, and we can help you better.
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