How to create a test script in Python for a registration page?
Question: I have a website made in PHP.

To increase number of data sets in my database, I need to create a python
script such that I need not add 500 registrations manually.

There are several tools available but I need to create script of my own.

Can any one help me with this ?

PS: I have knowledge of PHP, Python and ASP.NET as well.


Answer: # [MySQL](https://pypi.python.org/pypi/MySQL-python/)

    
    
    import MySQLdb
    
    db = MySQLdb.connect(host="localhost", user="john", passwd="megajonhy", db="jonhydb")
    cursor = db.cursor() 
    
    for i in range(0,500):
        cursor.execute("INSERT INTO MyTable VALUES('Some string', 1337);")
    

# [PostgreSQL](http://python.projects.pgfoundry.org/)

    
    
    import postgresql
    db = postgresql.open("pq://postgres:SupaPass@127.0.0.1/testdb")
    prepstatement = db.prepare("INSERT INTO MyTable VALUES($1, $2, $3);")
    with db.xact():
        for i in range(0, 500):
            prepstatement('Some string', 1337, ["a", "list"])
    

# [MsSQL](https://code.google.com/p/pyodbc/)

    
    
    import pyodbc
    cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=testdb;UID=user;PWD=pass')
    cursor = cnxn.cursor()
    for i in range(0, 500):
        cursor.execute("INSERT INTO MyTable VALUES('Some string', 1337);")
    

# [SQLAlchemy](http://www.sqlalchemy.org/)

Note that this is a library that will do a lot of magic for you, hence you'd
might not learn as much from it or desire all it's functionality.

    
    
    from sqlalchemy import create_engine
    db = create_engine("mssql://me:pass@localhost/testdb")
    for i in range(0, 500):
        db.execute("INSERT INTO MyTable VALUES('Some string', 1337);"):
    

# How get get POST/GET data

And finally, we have no clue as to how you run the script.  
But you mentioned web development and well, assuming you run the script as
CGI, here's how to get the POST/GET data:

    
    
    import cgi
    form = cgi.FieldStorage()
    print form["username"]
    

# Let me Google this for you

  * [How are POST and GET variables handled in Python?](http://stackoverflow.com/questions/464040/how-are-post-and-get-variables-handled-in-python)
  * [How do I connect to a MySQL Database in Python?](http://stackoverflow.com/questions/372885/how-do-i-connect-to-a-mysql-database-in-python)
  * [How to insert array of data into mysql using php](http://stackoverflow.com/questions/15013211/how-to-insert-array-of-data-into-mysql-using-php)
  * [MSSQL in python 2.7](http://stackoverflow.com/questions/7317195/mssql-in-python-2-7)

