Python Mysqldb Connection String

admin

Administrator
Staff member
Greetings:<br /><br />I am writing a python db script and am getting the infamous Premature end of script headers: <br /><br />#!/usr/bin/env python<br /><br /># import MySQL module<br />import MySQLdb<br /><br />db = MySQLdb.connect (host = "localhost"<br /> ,user = "myusername"<br /> ,passwd = "mypassword"<br /> ,db = "mydatabase")<br /># create a cursor<br />cursor = db.cursor()<br /># execute SQL statement<br />cursor.execute("SELECT * FROM category ORDER BY category ASC;")<br /># get the number of rows in the resultset<br />numrows = int(cursor.rowcount)<br /># get and display one row at a time in the select list<br />print "Content-Type: text/html\n\n"<br />print ... results from select statement.<br /><br />Is there a problem with how I am trying to connect to the database here? Is the syntax off for trying to connect to the db. Is MySQLdb for python installed on tch?<br /> A simple hello world script as follows works with no problems.<br /><br />#!/usr/bin/env python<br />print "Content-Type: text/html\n\n"<br />print "Hello World" <br /><br />Any python insights would be helpful. Thanks.<!--content-->
 
Back
Top