Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 mysql connector/telnet issue (re: text game)
#1
"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:"
------------------------------------
else:
                 
            def dbLookup(command):
                #connect to the database
                cnx = mysql.connector.connect(user='xxxx',
                                          password='xxxx',
                                          host='xxxx',
                                          port='xxxx',
                                          database='commands')
                #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))
                
                cursor.close()

                cnx.close()

            
            dbLookup(command)
-----------------------------
"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!"
Quote
#2
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,))

:)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  3.6 telnet eyler 3 3,922 Jun-28-2019, 05:22 AM
Last Post: Khanhamid90
  Any suggestion on python library to use for both ssh and telnet? lord_mani 4 415 Jun-25-2019, 04:07 PM
Last Post: gb74razor
  telnet question jacklee26 2 354 Mar-30-2019, 06:45 AM
Last Post: jacklee26
  Retrieve output from telnet command Networker 1 333 Mar-12-2019, 01:36 PM
Last Post: searching1
  GNS3 telnet from bash terminal to virtual cisco router marienbad 2 414 Feb-24-2019, 07:55 AM
Last Post: marienbad
  Telnet to switch from jump start server(linux) searching1 0 403 Jan-09-2019, 10:03 PM
Last Post: searching1
  Issue when running telnet program using python3 searching1 11 1,826 Dec-22-2018, 12:48 AM
Last Post: searching1
  Aggregate multiple telnet connections Jibeji 1 1,450 Mar-02-2018, 07:21 PM
Last Post: mpd
  Multithread telnet not working Parallel anna 7 1,959 Feb-05-2018, 01:17 PM
Last Post: anna
  telnetlib.Telnet timeout issue.. taking much time anna 1 2,672 Jan-19-2018, 01:52 PM
Last Post: devs4p

Forum Jump:


Users browsing this thread: 1 Guest(s)