hi i have a raspberry pi3.
I install php mysql et...
Now i want search if value is present in table.
helpppp!
my code is
import time
import MySQLdb
val = 'BBBBB'
db = MySQLdb.connect(host="localhost", user="", passwd="", db="")
#create a cursor for the select
cursor = db.cursor()
# if val exist in tabella1 then insert in tabella2
if
sql = "select * from tabella1 where valore = 'BBBBB' "
.....
....
anyone help me please
You are going to have to learn basic SQL.
One excellent tutorial is available
here
It's easy to learn, and you'll be doing basic queries in a short time.
What error do you get?
what is the actual code that you are using?
The indentation on the snippet you show is wrng, and would give an error.
What is the exact traceback that you are getting? please post (verbatim)
The syntax to select a particular field for a table would be
SELECT field FROM table WHERE otherfield = 'whatever';
Also you are not showing enough code, setting a string named sql is part of it,
but that string must be executed with the cursor
(Dec-15-2016, 10:53 PM)Larz60+ Wrote: [ -> ]What error do you get?
what is the actual code that you are using?
The indentation on the snippet you show is wrng, and would give an error.
What is the exact traceback that you are getting? please post (verbatim)
The syntax to select a particular field for a table would be
SELECT field FROM table WHERE otherfield = 'whatever';
Also you are not showing enough code, setting a string named sql is part of it,
but that string must be executed with the cursor
wonderful!!
works!!
great!
Ok i find value.
Now... if found value ...
How check that the search give result?
GREAT...
I HAVE A PROBLEM i must select... like variable....
so
SELECT valore from table WHERE valore LIKE ('%variable%');
...not work
What does "not work" mean? What error do you get?
import time
import MySQLdb
var = 'AAAA'
db = MySQLdb.connect(host="localhost", user="root", passwd="", db="db")
cursor = db.cursor()
sql = "select valore from tab where valore LIKE '%$var%' "
number_of_rows = cursor.execute(sql)
print(cursor.fetchone())
db.close()
result: None
That syntax looks correct to me.
what is your error?
(Dec-19-2016, 11:16 PM)Larz60+ Wrote: [ -> ]That syntax looks correct to me.
what is your error?
AAA value is in the tab of db