Permalink
Browse files

Add port to user identity and connection strings

  • Loading branch information...
1 parent c8c9a54 commit 2dd5f8a94356886b7148716889319ebdeeeb8e93 @ragol ragol committed Apr 24, 2013
View
@@ -50,7 +50,7 @@ function predie($_value) { pre($_value); Yii::app()->end(); }
if(!$app->user->isGuest)
{
- $app->db->connectionString = 'mysql:host=' . $app->user->host . ';dbname=information_schema';
+ $app->db->connectionString = 'mysql:host=' . $app->user->host . ';port=' . $app->user->port . ';dbname=information_schema';
$app->db->username= $app->user->name;
$app->db->password= $app->user->password;
$app->db->autoConnect = true;
@@ -25,17 +25,22 @@ class UserIdentity extends CUserIdentity
* @var string host
*/
public $host;
+ /**
+ * @var int port
+ */
+ public $port;
/**
* Constructor.
* @param string username
* @param string password
*/
- public function __construct($username,$password,$host)
+ public function __construct($username,$password,$host,$port)
{
$this->username=$username;
$this->password=$password;
$this->host=$host;
+ $this->port=$port;
}
/*
@@ -51,7 +56,7 @@ public function authenticate()
$db->username = $this->username;
$db->password = $this->password;
$db->emulatePrepare = true;
- $db->connectionString = 'mysql:host=' . $this->host . ';dbname=information_schema';
+ $db->connectionString = 'mysql:host=' . $this->host . ';dbname=information_schema;port=' . $this->port;
try {
@@ -66,6 +71,7 @@ public function authenticate()
$this->setState('settings', new UserSettingsManager($this->host, $this->username));
$this->setState('privileges', new UserPrivilegesManager($this->host, $this->username));
$this->setState("host", $this->host);
+ $this->setState("port", $this->port);
}
catch (CDbException $ex)
@@ -47,7 +47,8 @@ protected function connectDb($schema)
}
// Connect to database
- $this->db = new CDbConnection('mysql:host=' . Yii::app()->user->host . ';dbname=' . $schema . '; charset=utf8',
+ $connectionString = 'mysql:host=' . Yii::app()->user->host . ';port=' . Yii::app()->user->port . ';dbname=' . $schema . '; charset=utf8';
+ $this->db = new CDbConnection($connectionString,
utf8_decode(Yii::app()->user->name),
utf8_decode(Yii::app()->user->password));
$this->db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES \'utf8\'');
@@ -127,10 +128,10 @@ protected function sendJSON($data)
{
$content = $data;
}
-
+
header("Content-type: application/json");
echo $content;
Yii::app()->end();
}
-}
+}
@@ -63,9 +63,8 @@ public function __construct($id, $module = null)
protected function connectDb($schema)
{
// Connect to database
- $this->db = new CDbConnection('mysql:host=' . Yii::app()->user->host . ';dbname=mysql',
- Yii::app()->user->name,
- Yii::app()->user->password);
+ $connectionString = 'mysql:host=' . Yii::app()->user->host . ';port=' . Yii::app()->user->port . ';dbname=mysql';
+ $this->db = new CDbConnection($connectionString, Yii::app()->user->name, Yii::app()->user->password);
$this->db->charset = 'utf8';
$this->db->emulatePrepare = true;
@@ -378,4 +377,4 @@ public function actionDropSchema()
$this->sendJSON($response);
}
-}
+}

0 comments on commit 2dd5f8a

Please sign in to comment.