mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Implementing DboMysql::getVersion()
This commit is contained in:
parent
b8479459d6
commit
09e06d52b9
2 changed files with 33 additions and 2 deletions
|
@ -796,8 +796,17 @@ class DboMysql extends DboMysqlBase {
|
|||
*
|
||||
* @return string The database encoding
|
||||
*/
|
||||
function getEncoding() {
|
||||
return mysql_client_encoding($this->connection);
|
||||
public function getEncoding() {
|
||||
return $this->_execute('SHOW VARIABLES LIKE ?', array('character_set_client'))->fetchObject()->Value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the version string of the database server
|
||||
*
|
||||
* @return string The database encoding
|
||||
*/
|
||||
public function getVersion() {
|
||||
return $this->_execute('SELECT VERSION() as mysql_version')->fetchObject()->mysql_version;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -862,4 +862,26 @@ class DboMysqlTest extends CakeTestCase {
|
|||
$tables = $db->listSources();
|
||||
$this->assertEqual($tables, array('cake_table', 'another_table'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that getVersion method sends the correct query for getting the mysql version
|
||||
* @return void
|
||||
*/
|
||||
public function testGetVersion() {
|
||||
$db = $this->getMock('DboMysql', array('connect', '_execute'));
|
||||
$queryResult = $this->getMock('PDOStatement');
|
||||
|
||||
$db->expects($this->once())
|
||||
->method('_execute')
|
||||
->with('SELECT VERSION() as mysql_version')
|
||||
->will($this->returnValue($queryResult));
|
||||
$result = new StdClass;
|
||||
$result->mysql_version = '5.1';
|
||||
$queryResult->expects($this->once())
|
||||
->method('fetchObject')
|
||||
->will($this->returnValue($result));
|
||||
|
||||
$version = $db->getVersion();
|
||||
$this->assertEqual('5.1', $version);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue