Jun-19-2018, 08:43 AM
Hello World,
i've been searching for a while but i've found nothing so i post it here.
My problem is that I want to create a function that search for an id on a MySQL database which the row contains a certain word.
Here is my programm:
and it returns:
Basically it put quotes in the SQL syntax that i do not want and i don't know how to get rid of it. Do you have any idea?
Sorry for my English or if i did something wrong, first time posting on a forum
i've been searching for a while but i've found nothing so i post it here.
My problem is that I want to create a function that search for an id on a MySQL database which the row contains a certain word.
Here is my programm:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import MySQLdb def rechercheMySQL(): table = raw_input ( "Nom de la TABLE à explorer:" ) mot = raw_input ( "Mot à rechercher:" ) filtre = raw_input ( "Filtrer dans:" ) tri = raw_input ( "Trier par:" ) mydb = MySQLdb.connect(host = 'localhost' , user = 'root' , passwd = 'eisti0001' , db = 'DATAtourisme' ) cursor = mydb.cursor() SQL = "SELECT %s FROM %s WHERE %s LIKE %s" cursor.execute(SQL, (tri, table, filtre, mot)) if __name__ = = "__main__" : rechercheMySQL() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
python RechercheMYSQL.py Nom de la TABLE à explorer:Theatre Mot à rechercher:cerises Filtrer dans:commentaire Trier par: id Traceback (most recent call last): File "RechercheMYSQL.py" , line 21 , in <module> rechercheMySQL() File "RechercheMYSQL.py" , line 18 , in rechercheMySQL cursor.execute(SQL, (tri, table, filtre, mot)) File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py" , line 250 , in execute self .errorhandler( self , exc, value) File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py" , line 50 , in defaulterrorhandler raise errorvalue _mysql_exceptions.ProgrammingError: ( 1064 , "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 ''Theatre' WHERE 'commentaire' LIKE 'cerises'' at line 1" ) |
Sorry for my English or if i did something wrong, first time posting on a forum
