web: allow <db_host> to include :port

This commit is contained in:
David Anderson 2014-10-01 08:31:38 -07:00
parent 6518dddabd
commit 469b82ef0e
3 changed files with 23 additions and 6 deletions

View File

@ -27,10 +27,17 @@ class DbConn {
function init_conn($user, $passwd, $host, $name) {
if (MYSQLI) {
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
$this->db_conn = new mysqli($host, $user, $passwd);
$x = explode($host, ":");
if (sizeof($x)>1) {
$host = $x[0];
$port = $x[1];
} else {
$this->db_conn = new mysqli("p:".$host, $user, $passwd);
$port = null;
}
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
$this->db_conn = new mysqli($host, $user, $passwd, $name, $port);
} else {
$this->db_conn = new mysqli("p:".$host, $user, $passwd, $name, $port);
}
global $mysqli;
$mysqli = $this->db_conn;

View File

@ -255,8 +255,17 @@ def connect(config = None, nodb = False):
db = config.db_name
host=config.__dict__.get('db_host','')
port=""
if ':' in host:
host,port=config.__dict__.get('db_host','').split(":")
if port == '':
port = 3306
else:
port = int(port)
do_connect(db=db,
host=host,
port=port,
user=config.__dict__.get('db_user',''),
passwd=config.__dict__.get('db_passwd', ''))
return 1

View File

@ -488,14 +488,15 @@ class DatabaseObject:
def _set_dirty(self, value=True):
self.__dict__['_dirty'] = value
def do_connect(db, user, passwd, host='localhost'):
def do_connect(db, user, passwd, port, host='localhost'):
"""Takes a database name, a username, and password. Connects to
SQL server and makes a new Dbconnection."""
global dbconnection
if dbconnection:
raise 'Already connected'
dbconnection = MySQLdb.connect(db=db,host=host,user=user,passwd=passwd,
cursorclass=MySQLdb.cursors.DictCursor)
dbconnection = MySQLdb.connect(db=db, host=host, port=port, user=user,
passwd=passwd, cursorclass=MySQLdb.cursors.DictCursor)
def close():
"""Closes the connection to the sql survey and deletes the Dbconnection object."""
global dbconnection