How to run python programs on wamp server

How to run python in wamp server and mysql connectivity using python program

Steps:

  1. Create a simple python program file as following.
#!C:/Python27/python.exe
print “Content-type: text/html\n”
print “<h1 align=center>Python programming</h1>”
print “<hr>”
print “<h2>Hello, world!</h2>”
2. Save above file as “test.py ” in wamp ->www directory
3. Start wamp server
4. Open browser and type page url [as the following screen shot]

How to connect MySQL database using Python?

  1. 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 :
print
“<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

Share

1 thought on “How to run python programs on wamp server”

Comments are closed.

Share
Scroll to Top