PMC-337
This commit is contained in:
@@ -191,17 +191,19 @@ class MSSQLConnection extends ConnectionCommon implements Connection
|
||||
{
|
||||
$this->lastQuery = $sql;
|
||||
if (extension_loaded('sqlsrv')) {
|
||||
$result = sqlsrv_query($this->dblink, $sql);
|
||||
$result = @sqlsrv_query($this->dblink, $sql);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute query', print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
} else {
|
||||
if (!@mssql_select_db($this->database, $this->dblink)) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
$result = @mssql_query($sql, $this->dblink);
|
||||
}
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute query', mssql_get_last_message());
|
||||
}
|
||||
}
|
||||
return new MSSQLResultSet($this, $result, $fetchmode);
|
||||
}
|
||||
|
||||
@@ -210,23 +212,23 @@ class MSSQLConnection extends ConnectionCommon implements Connection
|
||||
*/
|
||||
function executeUpdate($sql)
|
||||
{
|
||||
if (extension_loaded('sqlsrv')) {
|
||||
$result = sqlsrv_query($this->dblink, $sql);
|
||||
} else {
|
||||
$this->lastQuery = $sql;
|
||||
if (extension_loaded('sqlsrv')) {
|
||||
$result = @sqlsrv_query($this->dblink, $sql);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute update', print_r(sqlsrv_errors(), true), $sql);
|
||||
}
|
||||
return (int) sqlsrv_rows_affected($this->dblink);
|
||||
} else {
|
||||
if (!mssql_select_db($this->database, $this->dblink)) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
|
||||
$result = @mssql_query($sql, $this->dblink);
|
||||
}
|
||||
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not execute update', mssql_get_last_message(), $sql);
|
||||
}
|
||||
|
||||
return (int) mssql_rows_affected($this->dblink);
|
||||
// return $this->getUpdateCount();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,14 +239,17 @@ class MSSQLConnection extends ConnectionCommon implements Connection
|
||||
protected function beginTrans()
|
||||
{
|
||||
if (extension_loaded('sqlsrv')) {
|
||||
$result = sqlsrv_begin_transaction($this->dblink);
|
||||
$result = @sqlsrv_begin_transaction($this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not begin transaction', print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
} else {
|
||||
$result = @mssql_query('BEGIN TRAN', $this->dblink);
|
||||
}
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not begin transaction', mssql_get_last_message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
@@ -254,17 +259,20 @@ class MSSQLConnection extends ConnectionCommon implements Connection
|
||||
protected function commitTrans()
|
||||
{
|
||||
if (extension_loaded('sqlsrv')) {
|
||||
$result = sqlsrv_commit($this->dblink);
|
||||
$result = @sqlsrv_commit($this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not commit transaction', print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
} else {
|
||||
if (!@mssql_select_db($this->database, $this->dblink)) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
$result = @mssql_query('COMMIT TRAN', $this->dblink);
|
||||
}
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not commit transaction', mssql_get_last_message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll back (undo) the current transaction.
|
||||
@@ -274,17 +282,20 @@ class MSSQLConnection extends ConnectionCommon implements Connection
|
||||
protected function rollbackTrans()
|
||||
{
|
||||
if (extension_loaded('sqlsrv')) {
|
||||
$result = sqlsrv_rollback($this->dblink);
|
||||
$result = @sqlsrv_rollback($this->dblink);
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not rollback transaction', print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
} else {
|
||||
if (!@mssql_select_db($this->database, $this->dblink)) {
|
||||
throw new SQLException('no database selected');
|
||||
}
|
||||
$result = @mssql_query('ROLLBACK TRAN', $this->dblink);
|
||||
}
|
||||
if (!$result) {
|
||||
throw new SQLException('Could not rollback transaction', mssql_get_last_message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by the last query.
|
||||
|
||||
@@ -154,13 +154,15 @@ class MSSQLResultSet extends ResultSetCommon implements ResultSet
|
||||
{
|
||||
if (extension_loaded('sqlsrv')) {
|
||||
$rows = @sqlsrv_num_rows($this->result);
|
||||
if ($rows === null) {
|
||||
throw new SQLException('Error getting record count', print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
} else {
|
||||
$rows = @mssql_num_rows($this->result);
|
||||
}
|
||||
|
||||
if ($rows === null) {
|
||||
throw new SQLException('Error getting record count', mssql_get_last_message());
|
||||
}
|
||||
}
|
||||
// adjust count based on emulated LIMIT/OFFSET
|
||||
$rows -= $this->offset;
|
||||
return ($this->limit > 0 && $rows > $this->limit ? $this->limit : $rows);
|
||||
|
||||
@@ -38,30 +38,29 @@ class MSSQLDatabaseInfo extends DatabaseInfo
|
||||
protected function initTables()
|
||||
{
|
||||
include_once 'creole/drivers/mssql/metadata/MSSQLTableInfo.php';
|
||||
|
||||
$dsn = $this->conn->getDSN();
|
||||
|
||||
|
||||
$sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME <> 'dtproperties'";
|
||||
if (extension_loaded('sqlsrv')) {
|
||||
$result = sqlsrv_query(
|
||||
"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME <> 'dtproperties'",
|
||||
$this->conn->getResource()
|
||||
);
|
||||
$result = sqlsrv_query($sql, $this->conn->getResource());
|
||||
if (!$result) {
|
||||
throw new SQLException("Could not list tables", print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
while ($row = sqlsrv_fetch_array($result)) {
|
||||
$this->tables[strtoupper($row[0])] = new MSSQLTableInfo($this, $row[0]);
|
||||
}
|
||||
} else {
|
||||
if (!@mssql_select_db($this->dbname, $this->conn->getResource())) {
|
||||
throw new SQLException('No database selected');
|
||||
}
|
||||
$result = mssql_query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME <> 'dtproperties'", $this->conn->getResource());
|
||||
}
|
||||
|
||||
$result = mssql_query($sql, $this->conn->getResource());
|
||||
if (!$result) {
|
||||
throw new SQLException("Could not list tables", mssql_get_last_message());
|
||||
}
|
||||
|
||||
while ($row = mssql_fetch_row($result)) {
|
||||
$this->tables[strtoupper($row[0])] = new MSSQLTableInfo($this, $row[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -253,14 +253,7 @@ class Net
|
||||
break;
|
||||
case 'mssql':
|
||||
//todo
|
||||
if (!extension_loaded('sqlsrv')) {
|
||||
if ($this->db_instance != "") {
|
||||
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
|
||||
} else {
|
||||
$port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":" . $this->db_port;
|
||||
$link = @mssql_connect($this->ip . $port, $this->db_user, $this->db_passwd);
|
||||
}
|
||||
} else {
|
||||
if (extension_loaded('sqlsrv')) {
|
||||
if ($this->db_instance != "") {
|
||||
$server = $this->ip . "\\" . $this->db_instance;
|
||||
} else {
|
||||
@@ -274,6 +267,13 @@ class Net
|
||||
'Database' => $this->db_sourcename
|
||||
];
|
||||
$link = @sqlsrv_connect($server, $opt);
|
||||
} else {
|
||||
if ($this->db_instance != "") {
|
||||
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
|
||||
} else {
|
||||
$port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":" . $this->db_port;
|
||||
$link = @mssql_connect($this->ip . $port, $this->db_user, $this->db_passwd);
|
||||
}
|
||||
}
|
||||
|
||||
if ($link) {
|
||||
@@ -397,14 +397,7 @@ class Net
|
||||
}
|
||||
break;
|
||||
case 'mssql':
|
||||
if (!extension_loaded('sqlsrv')) {
|
||||
if ($this->db_instance != "") {
|
||||
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
|
||||
} else {
|
||||
$port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":" . $this->db_port;
|
||||
$link = @mssql_connect($this->ip . $port, $this->db_user, $this->db_passwd);
|
||||
}
|
||||
} else {
|
||||
if (extension_loaded('sqlsrv')) {
|
||||
if ($this->db_instance != "") {
|
||||
$server = $this->ip . "\\" . $this->db_instance;
|
||||
} else {
|
||||
@@ -418,6 +411,13 @@ class Net
|
||||
'Database' => $this->db_sourcename
|
||||
];
|
||||
$link = $db = @sqlsrv_connect($server, $opt);
|
||||
} else {
|
||||
if ($this->db_instance != "") {
|
||||
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
|
||||
} else {
|
||||
$port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":" . $this->db_port;
|
||||
$link = @mssql_connect($this->ip . $port, $this->db_user, $this->db_passwd);
|
||||
}
|
||||
}
|
||||
if ($link) {
|
||||
if (!extension_loaded('sqlsrv')) {
|
||||
|
||||
Reference in New Issue
Block a user