0
我有一張PHP表格,我正在嘗試將其轉換爲Python。其中一個函數是mysql_fetch_array。有誰知道Python的等價物?正如你所看到的,我的大部分代碼已經被翻譯。 41行仍然是PHP的例外。Python版本的Python mysql_fetch_array
#send
import MySQLdb
servername = "localhost"
username = "username"
password = "password"
dbname = "some_database"
import time
today = time.strftime("%d-%m-%Y")
now = time.strftime("%H:%M:%S")
#use Django for this
field = request.GET['field']
value = request.GET['value']
conn = MySQLdb.connect(host="localhost",user="username",passwd="password",db=)
if not conn:
print 'Could not connect: mysql_error'# . mysql_error();
#below may need editing
con_result = conn.select("some_database")
if not con_result:
print 'Could not connect to specific database: '# . mysql_error();
datenow = today + ' ' + now
hvalue = value
sql = "INSERT INTO `DataTable`(`logdata`, `field`, `value`) VALUES (\"datenow\",\"field\",value)"
result = sql.fetchall()
if not result:
print 'Invalid query'
print "THE DATA HAS BEEN SENT!"
conn.close()
#get
fieldToGet = request.GET['field']
sql = "SELECT * FROM `DataTable` WHERE `field` = \"fieldToGet\""
result = sql.fetchall()
if not result:
print 'Invalid query'
print "THE DATA HAS BEEN RECEIVED!!"
while(row == mysql_fetch_array($result, MYSQL_ASSOC))
如何連接到MySQL?你有什麼調查?顯示一些代碼,並付出一些努力。 – miken32