Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 mysql connector/telnet issue (re: text game)
"Hi y'all, had a question about mysql connector and a text game I'm creating. I'm trying to make it so that a user will type something in (defined as "command" in my script), and then it will connect to my database and check their input command against a table, and return back a message associated with that command. For example, the player types a command that isn't part of the game yet, like "cry", and a table I've set up in my database has the first column as "idemotes", the second column as "emoteMsg". I want the game to output the "emoteMsg" to the player when they type in "cry", which might be "You sob like a little child." Snippet of my code is below:"
            def dbLookup(command):
                #connect to the database
                cnx = mysql.connector.connect(user='xxxx',
                #point the cursor to the database
                cursor = cnx.cursor()
                query = ("SELECT emoteMsg FROM emotes WHERE idemotes = '%s'")

                #perform the query and link %s to the player's command:
                cursor.execute(query, command)

                for (myMsg) in cursor:
                    mud.send_msg(id, "{}".format(emoteMsg))


"It works fine if I substitute '%s' in the query for an actual idemote value in the table, like 'cry'. But gets hung up if I put in that '%s', that I thought would match the command the player puts in to the idemote in the table and return only the emoteMsg value in that case. Feel like I'm getting some syntax incorrect here. Thanks in advance for any help!"
Nevermind, figured out the answer:

Need to make the query into a tuple, so mySQL can understand you. Stupid commas....

query = ("SELECT emoteMsg FROM emotes WHERE idemotes = '%s'", (command,))


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  telnet from ssh tunnel oldfart 1 137 Aug-10-2019, 06:44 PM
Last Post: DeaD_EyE
  3.6 telnet eyler 3 4,376 Jun-28-2019, 05:22 AM
Last Post: Khanhamid90
  Any suggestion on python library to use for both ssh and telnet? lord_mani 4 492 Jun-25-2019, 04:07 PM
Last Post: gb74razor
  telnet question jacklee26 2 410 Mar-30-2019, 06:45 AM
Last Post: jacklee26
  Retrieve output from telnet command Networker 1 406 Mar-12-2019, 01:36 PM
Last Post: searching1
  GNS3 telnet from bash terminal to virtual cisco router marienbad 2 476 Feb-24-2019, 07:55 AM
Last Post: marienbad
  Telnet to switch from jump start server(linux) searching1 0 457 Jan-09-2019, 10:03 PM
Last Post: searching1
  Issue when running telnet program using python3 searching1 11 2,113 Dec-22-2018, 12:48 AM
Last Post: searching1
  Aggregate multiple telnet connections Jibeji 1 1,544 Mar-02-2018, 07:21 PM
Last Post: mpd
  Multithread telnet not working Parallel anna 7 2,068 Feb-05-2018, 01:17 PM
Last Post: anna

Forum Jump:

Users browsing this thread: 1 Guest(s)