Bilgiler > Python Mysql Select Sorgusu Örneği
Python Mysql Select Sorgusu Örneği
from __future__ import print_function
hostname = '94.73.147.911'
username = 'u9162736_userDC61'
password = 'YASINcepeci2312311'
database = 'u9162736_dbDC61'
def doQuery( conn ) :
cur = conn.cursor()
cur.execute( "SELECT sensor_id,state FROM durum" )
for sensor_id, state in cur.fetchall() :
print( sensor_id, state )
print( "Using mysqlclient (MySQLdb):" )
import MySQLdb
myConnection = MySQLdb.connect( host=hostname, user=username, passwd=password, db=database)
doQuery( myConnection )
myConnection.close()
print("Using mysql.connector:")
import mysql.connector
myConnection = mysql.connector.connect(host=hostname, user=username, passwd=password, db=database)
doQuery(myConnection)
myConnection.close()
print("Using pymysql:")
import pymysql
myConnection = pymysql.connect(host=hostname, user=username, passwd=password, db=database)
doQuery(myConnection)
myConnection.close()
Kaynak:https://www.a2hosting.com/kb/d...ql-using-python
***