How to use select statements with variables in mysql in python

2015-11-28T23:04:17

I want to use a select statement with a variable within the where clause. Ive done resarch on this looking at How to use variables in SQL statement in Python? and Inserting Variables MySQL Using Python, Not Working. Ive tried to implement the solutions provided but its not working. Error code

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1

Heres the code:

name = input("Write your name")
mycursor.execute("SELECT name FROM workers WHERE symbol=?", name)

What am i doing wrong?

Copyright License:
Author:「Spike7」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/33972798/how-to-use-select-statements-with-variables-in-mysql-in-python

About “How to use select statements with variables in mysql in python” questions

I want to use a select statement with a variable within the where clause. Ive done resarch on this looking at How to use variables in SQL statement in Python? and Inserting Variables MySQL Using Py...
I have a series of MySql queries that need to be called with PDO. Many of them are using MySql variables. Surely, a solution would be to use PDO prepared statements but that's not always the case. ...
I have two mysql databases called database A and database B. I want to use python to copy all the data from a table in database A to a table in database B. The datatable holds approximately 5M rows...
I would like to use mysql variables to prevent same statements. In the following example i would like to sum the salary of an each employee and also sum it twice times. Of course the second column is
I'm writing a small program as part of a school assignment but i've been having trouble with sql statements. I was wondering if it were possible to use variables defined in the python code in sql
Are we able to enable prepared statements in Sequel for the MySQL2 database adapter? The documentation says that we can create prepared statements but the driver does not support bound variables....
I've been thinking, might it be possible to dynamically change MySQL select-statement with variables. ex. SET @infile=1; SELECT * IF( @infile ) INTO OUTFILE 'myfile.csv' ENDIF FROM my_table; O
I have two variables 1. inserted_user_id, 2. inserted_address_id in my MySQL procedure. I need to use them in insert queries and select queries. Im trying something like insert into user_new(
Please have a look at the below statement INSERT INTO Ongoing_Fees (currentDate, Gross_Fee, Insurance_Fee, Submit_Fee) SELECT current_timestamp, New.Gross_Fee, @InsuranceFee := (New.
Below is the code i'm trying to get to work: $y= "SELECT ('PRV_IDX') FROM LLS_PRIVILEGES WHERE `PRV_NAME` = 'Reader';"; mysql_query($y); $x= "SELECT (&#x

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.