How to run python in wamp server and mysql connectivity using python program
Steps:
- Create a simple python program file as following.
How to connect MySQL database using Python?
- Create a table in MySQL with the following record
2. Now create python program called “db5.py” as following
#!C:/Python27/python.exe
print “Content-type: text/html\n”
# Database program to access mysql data on WAMP server
print(“<h1> Python and MySQL Connection </h1>”)
print(“<hr>”)
import pymysql
conn=pymysql.connect(host=’localhost’, user=’root’,
password=”, db=’demo’)
a=conn.cursor()
sql=’SELECT * from emp’;
a.execute(sql)
countrow=a.execute(sql)data=a.fetchall()
print “<table border=1 cellpadding=4 cellspacing=4>”
print “<tr bgcolor=yellow><th> Name </th> <th> Basic
</th> <th> Bonus </th> <th> TA </th> <th> PF </th>
</tr>”
for row in data :
“<tr><td>”,row[0],”</td>”,”<td>”,row[1],”</td>”,”<td>”,
row[2],”</td>”,”<td>”,row[3],”</td>”,”<td>”,row[4],”</td
> </tr>”
print “</table>”
3. See the output as following
Best tutorial on python