mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
sqlsrv instances removed
This commit is contained in:
parent
058466ea87
commit
18789c5d84
@ -29,23 +29,6 @@ class MSSQLDatabase extends Database {
|
|||||||
*/
|
*/
|
||||||
private $database;
|
private $database;
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds either mssql or sqlsrv, depending on what's available on the server.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $funcPrefix;
|
|
||||||
|
|
||||||
/*function connect($server, $username, $password){
|
|
||||||
$func = $this->funcPrefix . '_connect';
|
|
||||||
|
|
||||||
|
|
||||||
if(MSSQL_COMPATIBLE)
|
|
||||||
return $func($server, $username, $password);
|
|
||||||
else
|
|
||||||
return sqlsrv_connect($server, $username, $password);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to a MS SQL database.
|
* Connect to a MS SQL database.
|
||||||
* @param array $parameters An map of parameters, which should include:
|
* @param array $parameters An map of parameters, which should include:
|
||||||
@ -56,25 +39,9 @@ class MSSQLDatabase extends Database {
|
|||||||
*/
|
*/
|
||||||
public function __construct($parameters) {
|
public function __construct($parameters) {
|
||||||
|
|
||||||
if(function_exists('sqlsrv_connect')){
|
$this->dbConn = mssql_connect($parameters['server'], $parameters['username'], $parameters['password']);
|
||||||
$this->funcPrefix='sqlsrv';
|
$this->active = mssql_select_db($parameters['database'], $this->dbConn);
|
||||||
$this->dbConn = sqlsrv_connect($parameters['server'], Array('UID'=>$parameters['username'], 'PWD'=>$parameters['password'], 'Database'=>$parameters['database']));
|
|
||||||
$this->query('USE ' . $parameters['database'] . ';');
|
|
||||||
$this->active=true;
|
|
||||||
} else {
|
|
||||||
$this->funcPrefix='mssql';
|
|
||||||
$this->dbConn = mssql_connect($parameters['server'], $parameters['username'], $parameters['password']);
|
|
||||||
$this->active = mssql_select_db($parameters['database'], $this->dbConn);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Set up the database function names
|
|
||||||
//$connect=$this->funcPrefix . '_connect';
|
|
||||||
//$select_db=$this->funcPrefix . '_select_db';
|
|
||||||
|
|
||||||
//assumes that the server and dbname will always be provided:
|
|
||||||
|
|
||||||
//$this->dbConn = $connect($parameters['server'], $parameters['username'], $parameters['password']);
|
|
||||||
//$this->active = $select_db($parameters['database'], $this->dbConn);
|
|
||||||
$this->database = $parameters['database'];
|
$this->database = $parameters['database'];
|
||||||
|
|
||||||
if(!$this->dbConn) {
|
if(!$this->dbConn) {
|
||||||
@ -82,7 +49,7 @@ class MSSQLDatabase extends Database {
|
|||||||
} else {
|
} else {
|
||||||
$this->active=true;
|
$this->active=true;
|
||||||
$this->database = $parameters['database'];
|
$this->database = $parameters['database'];
|
||||||
//$select_db($parameters['database'], $this->dbConn);
|
mssql_select_db($parameters['database'], $this->dbConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@ -168,22 +135,19 @@ class MSSQLDatabase extends Database {
|
|||||||
$starttime = microtime(true);
|
$starttime = microtime(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//echo 'sql: ' . $sql . '<br>';
|
echo 'sql: ' . $sql . '<br>';
|
||||||
//Debug::backtrace();
|
//Debug::backtrace();
|
||||||
|
|
||||||
//$funcName=$this->funcPrefix . '_query';
|
//if($sql!='')
|
||||||
|
|
||||||
if($this->funcPrefix=='mssql')
|
|
||||||
$handle = mssql_query($sql, $this->dbConn);
|
$handle = mssql_query($sql, $this->dbConn);
|
||||||
else
|
//else
|
||||||
$handle = sqlsrv_query($this->dbConn, $sql);
|
// $handle=null;
|
||||||
|
|
||||||
if(isset($_REQUEST['showqueries'])) {
|
if(isset($_REQUEST['showqueries'])) {
|
||||||
$endtime = round(microtime(true) - $starttime,4);
|
$endtime = round(microtime(true) - $starttime,4);
|
||||||
Debug::message("\n$sql\n{$endtime}ms\n", false);
|
Debug::message("\n$sql\n{$endtime}ms\n", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo 'handle for this query: ' . $handle . '<br>';
|
|
||||||
DB::$lastQuery=$handle;
|
DB::$lastQuery=$handle;
|
||||||
|
|
||||||
if(!$handle && $errorLevel) $this->databaseError("Couldn't run query: $sql", $errorLevel);
|
if(!$handle && $errorLevel) $this->databaseError("Couldn't run query: $sql", $errorLevel);
|
||||||
@ -677,8 +641,7 @@ class MSSQLDatabase extends Database {
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function affectedRows() {
|
public function affectedRows() {
|
||||||
$funcName=$this->funcPrefix . '_rows_affected';
|
return mssql_rows_affected($this->dbConn);
|
||||||
return $funcName($this->dbConn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1091,13 +1054,6 @@ class MSSQLQuery extends Query {
|
|||||||
*/
|
*/
|
||||||
private $handle;
|
private $handle;
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds either mssql or sqlsrv, depending on what's available on the server.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $funcPrefix;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook the result-set given into a Query class, suitable for use by sapphire.
|
* Hook the result-set given into a Query class, suitable for use by sapphire.
|
||||||
* @param database The database object that created this query.
|
* @param database The database object that created this query.
|
||||||
@ -1105,19 +1061,13 @@ class MSSQLQuery extends Query {
|
|||||||
*/
|
*/
|
||||||
public function __construct(MSSQLDatabase $database, $handle) {
|
public function __construct(MSSQLDatabase $database, $handle) {
|
||||||
|
|
||||||
if(function_exists('sqlsrv_connect'))
|
|
||||||
$this->funcPrefix='sqlsrv';
|
|
||||||
else
|
|
||||||
$this->funcPrefix='mssql';
|
|
||||||
|
|
||||||
$this->database = $database;
|
$this->database = $database;
|
||||||
$this->handle = $handle;
|
$this->handle = $handle;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destroy() {
|
public function __destroy() {
|
||||||
$funcName=$this->funcPrefix . '_free_result';
|
mssql_free_result($this->handle);
|
||||||
$funcName($this->handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1125,10 +1075,7 @@ class MSSQLQuery extends Query {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function seek($row) {
|
public function seek($row) {
|
||||||
if($this->funcPrefix=='mssql')
|
return mssql_data_seek($this->handle, $row);
|
||||||
return mssql_data_seek($this->handle, $row);
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1141,55 +1088,24 @@ class MSSQLQuery extends Query {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function numRecords() {
|
public function numRecords() {
|
||||||
if($this->funcPrefix=='mssql')
|
return mssql_num_rows($this->handle);
|
||||||
return mssql_num_rows($this->handle);
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nextRecord() {
|
public function nextRecord() {
|
||||||
//echo 'running nextRecord<br>';
|
|
||||||
// Coalesce rather than replace common fields.
|
// Coalesce rather than replace common fields.
|
||||||
if($this->funcPrefix=='mssql'){
|
if($data = mssql_fetch_row($this->handle)) {
|
||||||
if($data = mssql_fetch_row($this->handle)) {
|
foreach($data as $columnIdx => $value) {
|
||||||
foreach($data as $columnIdx => $value) {
|
$columnName = mssql_field_name($this->handle, $columnIdx);
|
||||||
$columnName = mssql_field_name($this->handle, $columnIdx);
|
// $value || !$ouput[$columnName] means that the *last* occurring value is shown
|
||||||
// $value || !$ouput[$columnName] means that the *last* occurring value is shown
|
// !$ouput[$columnName] means that the *first* occurring value is shown
|
||||||
// !$ouput[$columnName] means that the *first* occurring value is shown
|
if(isset($value) || !isset($output[$columnName])) {
|
||||||
if(isset($value) || !isset($output[$columnName])) {
|
$output[$columnName] = $value;
|
||||||
$output[$columnName] = $value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//echo 'output from nextRecord (MSSQL):<pre>';
|
|
||||||
//print_r($output);
|
|
||||||
//echo '</pre>';
|
|
||||||
return $output;
|
|
||||||
} else {
|
|
||||||
//echo 'nothing to return from nextRecord<br>';
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
} else {
|
} else {
|
||||||
//Data returns true or false, NOT the actual row
|
return false;
|
||||||
if($data = sqlsrv_fetch($this->handle)) {
|
|
||||||
//Now we need to get each row as a stream
|
|
||||||
//foreach($data as $columnIdx => $value) {
|
|
||||||
while($row=sqlsrv_get_field(DB::$lastQuery)){
|
|
||||||
$columnName = sqlsrv_field_name($this->handle, $columnIdx);
|
|
||||||
// $value || !$ouput[$columnName] means that the *last* occurring value is shown
|
|
||||||
// !$ouput[$columnName] means that the *first* occurring value is shown
|
|
||||||
if(isset($value) || !isset($output[$columnName])) {
|
|
||||||
$output[$columnName] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//echo 'output from nextRecord (SQLSRV):<pre>';
|
|
||||||
//print_r($output);
|
|
||||||
//echo '</pre>';
|
|
||||||
return $output;
|
|
||||||
} else {
|
|
||||||
//echo 'nothing to return from nextRecord<br>';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user