Friday 18 November 2011

Python code for inserting a row into MySQL database

Here is the code that can be used to insert a row into MySQL using Python

#!C:/Python25/python.exe -u
import MySQLdb print "Content-type: text/html" db=MySQLdb.connect(host="localhost",user="xxxx",passwd="",db="xxxxxx") cursor=db.cursor() \
import socket \
timeout=10
a=1
socket.setdefaulttimeout(timeout)
from urllib2 import Request, urlopen, URLError, HTTPError
url="http://www.rediff.com"
req = Request(url)
try:
response = urlopen(req)
except:
print 'error'

the_page=response.read()
no=1
cursor.execute('INSERT INTO testing values("%s","%s")' % \ (no,the_page))

4 comments:

  1. You did an amazing job. I really enjoyed reading this blog. I like and appreciate your work. Thank you for Sharing such an amazing article.
    FateBook
    TrendMiner
    Hawaar
    Papaly
    Flipboard
    Mewe
    TrendMiners
    Plurk

    ReplyDelete
  2. Call forwarding is a convenient option which helps you to forward calls to any other number. It is not compulsory to call forwarding all the calls. Rather than, you can forward calls while you are on the call.

    When the server faces any error because of some reason, then you need to fix it before there is any impact on the system. Nowadays, all the things are done online. If you want to know the step to use SAM to monitor your server and applications, then follow the steps mentioned in this article.

    ReplyDelete
  3. Primevideo.com/mytv activation code is a 6-digit that seems on your TV screen if you click on “Register on the Amazon Prime website”. Then, the prime video activation code is what you will enter when you go to Primevideo.com/myTV and login to your Prime video 7-days free trial or paid account if you have upgraded.
    Read more…

    ReplyDelete