|Home About Us Services Clients Resources Blog Careers Orderbox™||contact us Site map links|
In Spyce, we use a convention where we tuck away the connection details in a module,
<%\ import MySQLdb con=MySQLdb.Connect( host="foobar.com", port=3306, user="loginname", passwd="loginpassword", db="foobar") %>
<%\ from dbfoobar import con con.ping(True) cur=con.cursor() %>
The method above ensures an automatic reconnection if the server ever goes away and should no longer display the error 2006 message. The pydoc documentation for ping() has full details:
>>> import MySQLdb >>> help(MySQLdb._mysql.connection.ping) Help on method_descriptor: ping(...) Checks whether or not the connection to the server is working. If it has gone down, an automatic reconnection is attempted. This function can be used by clients that remain idle for a long while, to check whether or not the server has closed the connection and reconnect if necessary. New in 1.2.2: Accepts an optional reconnect parameter. If True, then the client will attempt reconnection. Note that this setting is persistent. By default, this is on in MySQL<5.0.3, and off thereafter. Non-standard. You should assume that ping() performs an implicit rollback; use only when starting a new transaction. You have been warned.
Want to tip via bitcoin?
(address string below for double checking)
© 2017 by Andy Sy
Web Development / Rich Internet Applications (RIA) Development
|© 2003-2015 Neotitans Technologies Inc.||contact/hire us|