Jump to content

Recommended Posts

Posted

Greetings:

 

I am writing a python db script and am getting the infamous Premature end of script headers:

 

#!/usr/bin/env python

 

# import MySQL module

import MySQLdb

 

db = MySQLdb.connect (host = "localhost"

,user = "myusername"

,passwd = "mypassword"

,db = "mydatabase")

# create a cursor

cursor = db.cursor()

# execute SQL statement

cursor.execute("SELECT * FROM category ORDER BY category ASC;")

# get the number of rows in the resultset

numrows = int(cursor.rowcount)

# get and display one row at a time in the select list

print "Content-Type: text/html\n\n"

print ... results from select statement.

 

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?

A simple hello world script as follows works with no problems.

 

#!/usr/bin/env python

print "Content-Type: text/html\n\n"

print "Hello World"

 

Any python insights would be helpful. Thanks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...