Python Forum
Problem Using SQL Placeholder In MySQL Query
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem Using SQL Placeholder In MySQL Query
#1
Hi all, I'm very new to Python (7 days and counting) and seem to be having problems with passing in variables into my SELECT query.

The intention is to use the value selected from a combo box as the condition in the WHERE clause.

Please note that I'm using VS Code 1.5.8.2, MySQL 8.0.20, Python3

I have tried the ? method and it didn't work, I then tried the %s but nothing was returned. Below is the snippet
in question (sincere apologies for the dire quality of my coding):

#note that mycmb holds the value selected from the combo box

sql = "SELECT * FROM tbl_colours WHERE pc_name = %s"
mycmb = (cmb1.get(), )

mycursor = mydb.cursor();
mycursor.execute(sql, mycmb)
myresult = mycursor.fetchall();

I don't have a clue what the problem is and have tried all solutions found on the web.
Any help would be appreciated.
Reply


Messages In This Thread
Problem Using SQL Placeholder In MySQL Query - by AdeS - Jul-28-2021, 03:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql and mysql.connector error lostintime 2 865 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,905 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  Problem updating value in MySQL database dangermaus33 1 1,732 Nov-24-2020, 08:32 PM
Last Post: dangermaus33
  MYSQL Update Query format simdo01 1 2,323 Aug-31-2020, 12:59 AM
Last Post: nilamo
  Python mysql query help please tduckman 4 4,501 Mar-13-2020, 03:42 PM
Last Post: Marbelous
  Problem with bindnig for query DT2000 16 8,548 Mar-21-2019, 01:50 AM
Last Post: DT2000
  Looking for an up to date example to query mysql UtiliseIT 5 3,755 Feb-19-2019, 05:35 AM
Last Post: UtiliseIT
  MySQL INSERT Problem gw1500se 5 4,121 Jul-13-2018, 10:27 AM
Last Post: buran
  Problem with Python, MySQL and Multi-threading queries zagk 1 12,080 Jul-01-2017, 12:15 AM
Last Post: zagk
  MySQLdb, problem with query with user-defined variables buran 6 6,644 Feb-03-2017, 06:16 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020