RE: [Zope] using a ZMySQL database connection object in an external method
Hi, instead of giving the connection object to python, you can create a new one... mycon = MySQLdb.Connection( db=mydb, host=myhost, user=myuser, passwd=mypwd ) Then, you can ask for the cursor of the connection object : mycursor = mycon.cursor() And execute a query like this : mycursor.execute( myquery ) raw_datas = mycursor.fetchall() Finaly, you can close the connection : mycon.close() But I wonder if it's really what you need... Why do you can to access databases from an external method ??? Frederic Quin ########################################################################## Is there a How-To, or are there some code fragments that will help me use a ZMySQL (or a psycopg) database connection object in an external method? Given that mysql_connection is a ZMySQL database connection object, I expected mysql_connection.db.select_db('database') to work. But I got Error Type: ProgrammingError Error Value: (2014, "Commands out of sync; You can't run this command now") Any help is appreciated. cheers, Luby
Frederic, thank you so much for the enlightenment. I use external methods becuase I want to use other modules such as HTMLgen. My intent of connecting to databases directly from external methods is to generate sql dynamically. I suspect that ZSQL framework might cause a proliferation of ZSQL methods. cheers, Luby
Hi, instead of giving the connection object to python, you can create a new one... mycon = MySQLdb.Connection( db=mydb, host=myhost, user=myuser, passwd=mypwd )
Then, you can ask for the cursor of the connection object : mycursor = mycon.cursor()
And execute a query like this : mycursor.execute( myquery ) raw_datas = mycursor.fetchall()
Finaly, you can close the connection : mycon.close()
But I wonder if it's really what you need... Why do you can to access databases from an external method ???
Frederic Quin
########################################################################## Is there a How-To, or are there some code fragments that will help me use a ZMySQL (or a psycopg) database connection object in an external method? Given that mysql_connection is a ZMySQL database connection object, I expected
mysql_connection.db.select_db('database')
to work. But I got
Error Type: ProgrammingError Error Value: (2014, "Commands out of sync; You can't run this command now")
Any help is appreciated. cheers, Luby
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (2)
-
Frederic Quin -
Luby Liao