Rolly Maulana Awangga :: Catatan Ngoprek IT

Pakar dan Awam sama saja, sama sama belajar

Python Beginner : Mysql Query

Start with this tutorials

http://ianhowson.com/a-quick-guide-to-using-mysql-in-python.html

i create script

import MySQLdb
import gc
gc.collect()

db = MySQLdb.connect(host=”localhost”, # your host, usually localhost
user=”user”, # your username
passwd=”password”, # your password
db=”db”) # name of the data base

# you must create a Cursor object. It will let
# you execute all the queries you need
cur = db.cursor()

# Use all the SQL you like
cur.execute(“SELECT * FROM db where status=3”)
hasil=cur.fetchone()
db.close()

id_ref = hasil[0]
timestamp_req = hasil[1]
file_path = hasil[2]
status = hasil[3]
secret_code = hasil[4]
id_user = hasil[5]
id_user_acc = hasil[6]
timestamp_acc = hasil[7]
message = hasil[8]
tahun = hasil[9]

print file_path
print “perintah untuk pengambilan data db sudah ok”

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: