This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

MySQL query's & TCL

Old posts that have not been replied to for several years.
Locked
A
Afwezig

MySQL query's & TCL

Post by Afwezig »

Hi,

Let's start with to say I'm a complete newbie in TCL / Eggdrop coding (Coded primarily PHP in my life ;) ). However, I tried allmost everything to find out how this works, but I really wouldn't know where to search. (I tried the search function on this forum also, but that wasn't much of a help either ;) )
Well, here is my really basic script ;) :

Code: Select all

set dbhost "*****"
set dbuser "*****"
set dbpass "*****"
set dbname "*****"

proc pub_score {nick uhost hand channel arg} {
  global usertable botnick dbuser dbname dbpass dbhost
   sql connect $dbhost $dbuser $dbpass
   sql selectdb $dbname
   if {$arg == ""} {
    puthelp "NOTICE $nick :USAGE: !score <nick>"
    sql disconnect
    return 0
   } {
    set scorez [lrange $arg 0 end]
    set row [sql "SELECT score FROM table WHERE user='$scorez'"]
    set score [lindex $row 0]
    puthelp "NOTICE $nick :$scorez has score $table(score)"
    sql disconnect
    return 0
   }
}

bind pub - !score pub_score
In case you completely don't understand what the meaning of this script is : I want to query the value of 'score' from the table 'table' in my mysql database. The login on the database seems to work (it doesn't crash, so I suppose it works). I loaded the fbsql.so script in my conf file.
Anyone got any hints for me to go on ? :) Thanx in advance
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Read the docs! Don't just invent stuff when you're stuck...like
$table(score)
Your variable 'row' will contain a list of rows being lists themselves...so to access the first row retrieved you'd have to use [lindex $row 0] and to retrieve the first column of that row it'd be [lindex [lindex $row 0] 0].

I've never used fastbase, but at least that's how it's supposed to work according to the docs. (http://www.fastbase.co.nz/fbsql/fbsql.html)
Locked