Ruby mysql lib compare with Python mysql lib

#Lib include:
#Ruby:
require "mysql"
#Python:
import MySQLdb as mdb

#Connect db
#Ruby:
dbh = Mysql.real_connect("localhost", "test", "test", "rubydb")
#Python:
conn = mdb.connect('localhost', 'testuser', 'test623', 'testdb')

#Execute SQL:
#Ruby:
dbh.query("SELECT * FROM database")
#Python:
cursor = conn.cursor()
cursor.execute("SELECT * FROM database")

#Get the data:
#Ruby:
res = dbh.query("SELECT * FROM database")
while row = res.fetch_row do
         puts row
end
#Python:
cursor.execute("SELECT * FROM database")
rows = cusor.fetchall()
for row in rows:
        print row

#Close database:
#Ruby
dbh.close
#Python
mdb.clsoe


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章