Rofi Fathurrohman
Rofi Fathurrohman

Reputation: 167

Select column in one row and save as variable using python and mysqldb

first sorry for my bad english. i'm php programmer and I just started a python programming language.

Mysql code:

SELECT * FROM `datapy` ORDER BY `No` DESC LIMIT 0,1

And show row:

++++++++++++++++++
++ NO +++ nilai ++
++++++++++++++++++
++ 12 +++  100  ++
++++++++++++++++++

in php it's very easy for select column and save as variable using:

$row = $takecolumn['nilai'];

What should I do if in python using mysqldb?

Upvotes: 0

Views: 347

Answers (1)

Dipnesh Parakhiya
Dipnesh Parakhiya

Reputation: 542

you can create a database object like db and use cursor()

cur=db.cursor()
cur.execute("select nilai from datapy ORDER BY `No` DESC LIMIT 0,1")
rows = cur.fetchall()

Upvotes: 1

Related Questions