php - Scripting mysql for retrieving data in a loop -
php - Scripting mysql for retrieving data in a loop -
background: non developer bash shell scripting knowledge needs query read db instance , generate info given variables.
data in existing file
a1 b1 a2 b2 ...... ... .... bn
i connect mysql database within bash script , loop through select statement "n" number of times
select x, y,z table tablet_vendors a=a1 , b=b1
except a1 , b1 need passed parameters first time, a2 , b2 next time , n in loop. know shell side of things, don't know how integrate both.
tried can define possible values "a" @ origin of shell script, it's way tedious. help appreciated.
i open suggestions on using other scripting languages if easy work mysql , if can provide guidance. searches pointing php , python??
here's simpler version:
import mysqldb mysql import csv con = mysql.connect('localhost','user','password','dbname') cur = con.cursor() q = "select x, y,z tablet_vendors a=%s , b=%s" open('somefile.txt') f: rows = csv.reader(f,delimiter='\t') row in rows: cur.execute(q,row) result = cur.fetchone() while result: print result result = cur.fetchone()
any errors thrown mysql stop execution. can wrap cur.
lines in try/except block more elegant.
php python mysql shell scripting
Comments
Post a Comment