Sqlsrv.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Db
  17. * @subpackage Adapter
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Db_Adapter_Abstract
  23. */
  24. require_once 'Zend/Db/Adapter/Abstract.php';
  25. /**
  26. * @see Zend_Db_Statement_Sqlsrv
  27. */
  28. require_once 'Zend/Db/Statement/Sqlsrv.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Db
  32. * @subpackage Adapter
  33. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
  37. {
  38. /**
  39. * User-provided configuration.
  40. *
  41. * Basic keys are:
  42. *
  43. * username => (string) Connect to the database as this username.
  44. * password => (string) Password associated with the username.
  45. * dbname => The name of the local SQL Server instance
  46. *
  47. * @var array
  48. */
  49. protected $_config = array(
  50. 'dbname' => null,
  51. 'username' => null,
  52. 'password' => null,
  53. );
  54. /**
  55. * Last insert id from INSERT query
  56. *
  57. * @var int
  58. */
  59. protected $_lastInsertId;
  60. /**
  61. * Query used to fetch last insert id
  62. *
  63. * @var string
  64. */
  65. protected $_lastInsertSQL = 'SELECT SCOPE_IDENTITY() as Current_Identity';
  66. /**
  67. * Keys are UPPERCASE SQL datatypes or the constants
  68. * Zend_Db::INT_TYPE, Zend_Db::BIGINT_TYPE, or Zend_Db::FLOAT_TYPE.
  69. *
  70. * Values are:
  71. * 0 = 32-bit integer
  72. * 1 = 64-bit integer
  73. * 2 = float or decimal
  74. *
  75. * @var array Associative array of datatypes to values 0, 1, or 2.
  76. */
  77. protected $_numericDataTypes = array(
  78. Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
  79. Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
  80. Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
  81. 'INT' => Zend_Db::INT_TYPE,
  82. 'SMALLINT' => Zend_Db::INT_TYPE,
  83. 'TINYINT' => Zend_Db::INT_TYPE,
  84. 'BIGINT' => Zend_Db::BIGINT_TYPE,
  85. 'DECIMAL' => Zend_Db::FLOAT_TYPE,
  86. 'FLOAT' => Zend_Db::FLOAT_TYPE,
  87. 'MONEY' => Zend_Db::FLOAT_TYPE,
  88. 'NUMERIC' => Zend_Db::FLOAT_TYPE,
  89. 'REAL' => Zend_Db::FLOAT_TYPE,
  90. 'SMALLMONEY' => Zend_Db::FLOAT_TYPE,
  91. );
  92. /**
  93. * Default class name for a DB statement.
  94. *
  95. * @var string
  96. */
  97. protected $_defaultStmtClass = 'Zend_Db_Statement_Sqlsrv';
  98. /**
  99. * Creates a connection resource.
  100. *
  101. * @return void
  102. * @throws Zend_Db_Adapter_Sqlsrv_Exception
  103. */
  104. protected function _connect()
  105. {
  106. if (is_resource($this->_connection)) {
  107. // connection already exists
  108. return;
  109. }
  110. if (!extension_loaded('sqlsrv')) {
  111. /**
  112. * @see Zend_Db_Adapter_Sqlsrv_Exception
  113. */
  114. require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
  115. throw new Zend_Db_Adapter_Sqlsrv_Exception('The Sqlsrv extension is required for this adapter but the extension is not loaded');
  116. }
  117. $serverName = $this->_config['host'];
  118. if (isset($this->_config['port'])) {
  119. $port = (integer) $this->_config['port'];
  120. $serverName .= ', ' . $port;
  121. }
  122. $connectionInfo = array(
  123. 'Database' => $this->_config['dbname'],
  124. );
  125. if (isset($this->_config['username']) && isset($this->_config['password']))
  126. {
  127. $connectionInfo += array(
  128. 'UID' => $this->_config['username'],
  129. 'PWD' => $this->_config['password'],
  130. );
  131. }
  132. // else - windows authentication
  133. if (!empty($this->_config['driver_options'])) {
  134. foreach ($this->_config['driver_options'] as $option => $value) {
  135. // A value may be a constant.
  136. if (is_string($value)) {
  137. $constantValue = @constant(strtoupper($value));
  138. if ($constantValue === null) {
  139. $connectionInfo[$option] = $value;
  140. } else {
  141. $connectionInfo[$option] = $constantValue;
  142. }
  143. }
  144. }
  145. }
  146. $this->_connection = sqlsrv_connect($serverName, $connectionInfo);
  147. if (!$this->_connection) {
  148. /**
  149. * @see Zend_Db_Adapter_Sqlsrv_Exception
  150. */
  151. require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
  152. throw new Zend_Db_Adapter_Sqlsrv_Exception(sqlsrv_errors());
  153. }
  154. }
  155. /**
  156. * Check for config options that are mandatory.
  157. * Throw exceptions if any are missing.
  158. *
  159. * @param array $config
  160. * @throws Zend_Db_Adapter_Exception
  161. */
  162. protected function _checkRequiredOptions(array $config)
  163. {
  164. // we need at least a dbname
  165. if (! array_key_exists('dbname', $config)) {
  166. /** @see Zend_Db_Adapter_Exception */
  167. require_once 'Zend/Db/Adapter/Exception.php';
  168. throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'dbname' that names the database instance");
  169. }
  170. if (! array_key_exists('password', $config) && array_key_exists('username', $config)) {
  171. /**
  172. * @see Zend_Db_Adapter_Exception
  173. */
  174. require_once 'Zend/Db/Adapter/Exception.php';
  175. throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'password' for login credentials.
  176. If Windows Authentication is desired, both keys 'username' and 'password' should be ommited from config.");
  177. }
  178. if (array_key_exists('password', $config) && !array_key_exists('username', $config)) {
  179. /**
  180. * @see Zend_Db_Adapter_Exception
  181. */
  182. require_once 'Zend/Db/Adapter/Exception.php';
  183. throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'username' for login credentials.
  184. If Windows Authentication is desired, both keys 'username' and 'password' should be ommited from config.");
  185. }
  186. }
  187. /**
  188. * Set the transaction isoltion level.
  189. *
  190. * @param integer|null $level A fetch mode from SQLSRV_TXN_*.
  191. * @return true
  192. * @throws Zend_Db_Adapter_Sqlsrv_Exception
  193. */
  194. public function setTransactionIsolationLevel($level = null)
  195. {
  196. $this->_connect();
  197. $sql = null;
  198. // Default transaction level in sql server
  199. if ($level === null)
  200. {
  201. $level = SQLSRV_TXN_READ_COMMITTED;
  202. }
  203. switch ($level) {
  204. case SQLSRV_TXN_READ_UNCOMMITTED:
  205. $sql = "READ UNCOMMITTED";
  206. break;
  207. case SQLSRV_TXN_READ_COMMITTED:
  208. $sql = "READ COMMITTED";
  209. break;
  210. case SQLSRV_TXN_REPEATABLE_READ:
  211. $sql = "REPEATABLE READ";
  212. break;
  213. case SQLSRV_TXN_SNAPSHOT:
  214. $sql = "SNAPSHOT";
  215. break;
  216. case SQLSRV_TXN_SERIALIZABLE:
  217. $sql = "SERIALIZABLE";
  218. break;
  219. default:
  220. require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
  221. throw new Zend_Db_Adapter_Sqlsrv_Exception("Invalid transaction isolation level mode '$level' specified");
  222. }
  223. if (!sqlsrv_query($this->_connection, "SET TRANSACTION ISOLATION LEVEL $sql;")) {
  224. require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
  225. throw new Zend_Db_Adapter_Sqlsrv_Exception("Transaction cannot be changed to '$level'");
  226. }
  227. return true;
  228. }
  229. /**
  230. * Test if a connection is active
  231. *
  232. * @return boolean
  233. */
  234. public function isConnected()
  235. {
  236. return (is_resource($this->_connection)
  237. && (get_resource_type($this->_connection) == 'SQL Server Connection')
  238. );
  239. }
  240. /**
  241. * Force the connection to close.
  242. *
  243. * @return void
  244. */
  245. public function closeConnection()
  246. {
  247. if ($this->isConnected()) {
  248. sqlsrv_close($this->_connection);
  249. }
  250. $this->_connection = null;
  251. }
  252. /**
  253. * Returns an SQL statement for preparation.
  254. *
  255. * @param string $sql The SQL statement with placeholders.
  256. * @return Zend_Db_Statement_Sqlsrv
  257. */
  258. public function prepare($sql)
  259. {
  260. $this->_connect();
  261. $stmtClass = $this->_defaultStmtClass;
  262. if (!class_exists($stmtClass)) {
  263. /**
  264. * @see Zend_Loader
  265. */
  266. require_once 'Zend/Loader.php';
  267. Zend_Loader::loadClass($stmtClass);
  268. }
  269. $stmt = new $stmtClass($this, $sql);
  270. $stmt->setFetchMode($this->_fetchMode);
  271. return $stmt;
  272. }
  273. /**
  274. * Quote a raw string.
  275. *
  276. * @param string $value Raw string
  277. * @return string Quoted string
  278. */
  279. protected function _quote($value)
  280. {
  281. if (is_int($value)) {
  282. return $value;
  283. } elseif (is_float($value)) {
  284. return sprintf('%F', $value);
  285. }
  286. return "'" . str_replace("'", "''", $value) . "'";
  287. }
  288. /**
  289. * Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
  290. *
  291. * As a convention, on RDBMS brands that support sequences
  292. * (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
  293. * from the arguments and returns the last id generated by that sequence.
  294. * On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
  295. * returns the last value generated for such a column, and the table name
  296. * argument is disregarded.
  297. *
  298. * @param string $tableName OPTIONAL Name of table.
  299. * @param string $primaryKey OPTIONAL Name of primary key column.
  300. * @return string
  301. */
  302. public function lastInsertId($tableName = null, $primaryKey = null)
  303. {
  304. if ($tableName) {
  305. $tableName = $this->quote($tableName);
  306. $sql = 'SELECT IDENT_CURRENT (' . $tableName . ') as Current_Identity';
  307. return (string) $this->fetchOne($sql);
  308. }
  309. if ($this->_lastInsertId > 0) {
  310. return (string) $this->_lastInsertId;
  311. }
  312. $sql = $this->_lastInsertSQL;
  313. return (string) $this->fetchOne($sql);
  314. }
  315. /**
  316. * Inserts a table row with specified data.
  317. *
  318. * @param mixed $table The table to insert data into.
  319. * @param array $bind Column-value pairs.
  320. * @return int The number of affected rows.
  321. */
  322. public function insert($table, array $bind)
  323. {
  324. // extract and quote col names from the array keys
  325. $cols = array();
  326. $vals = array();
  327. foreach ($bind as $col => $val) {
  328. $cols[] = $this->quoteIdentifier($col, true);
  329. if ($val instanceof Zend_Db_Expr) {
  330. $vals[] = $val->__toString();
  331. unset($bind[$col]);
  332. } else {
  333. $vals[] = '?';
  334. }
  335. }
  336. // build the statement
  337. $sql = "INSERT INTO "
  338. . $this->quoteIdentifier($table, true)
  339. . ' (' . implode(', ', $cols) . ') '
  340. . 'VALUES (' . implode(', ', $vals) . ')'
  341. . ' ' . $this->_lastInsertSQL;
  342. // execute the statement and return the number of affected rows
  343. $stmt = $this->query($sql, array_values($bind));
  344. $result = $stmt->rowCount();
  345. $stmt->nextRowset();
  346. $this->_lastInsertId = $stmt->fetchColumn();
  347. return $result;
  348. }
  349. /**
  350. * Returns a list of the tables in the database.
  351. *
  352. * @return array
  353. */
  354. public function listTables()
  355. {
  356. $this->_connect();
  357. $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
  358. return $this->fetchCol($sql);
  359. }
  360. /**
  361. * Returns the column descriptions for a table.
  362. *
  363. * The return value is an associative array keyed by the column name,
  364. * as returned by the RDBMS.
  365. *
  366. * The value of each array element is an associative array
  367. * with the following keys:
  368. *
  369. * SCHEMA_NAME => string; name of schema
  370. * TABLE_NAME => string;
  371. * COLUMN_NAME => string; column name
  372. * COLUMN_POSITION => number; ordinal position of column in table
  373. * DATA_TYPE => string; SQL datatype name of column
  374. * DEFAULT => string; default expression of column, null if none
  375. * NULLABLE => boolean; true if column can have nulls
  376. * LENGTH => number; length of CHAR/VARCHAR
  377. * SCALE => number; scale of NUMERIC/DECIMAL
  378. * PRECISION => number; precision of NUMERIC/DECIMAL
  379. * UNSIGNED => boolean; unsigned property of an integer type
  380. * PRIMARY => boolean; true if column is part of the primary key
  381. * PRIMARY_POSITION => integer; position of column in primary key
  382. * IDENTITY => integer; true if column is auto-generated with unique values
  383. *
  384. * @todo Discover integer unsigned property.
  385. *
  386. * @param string $tableName
  387. * @param string $schemaName OPTIONAL
  388. * @return array
  389. */
  390. public function describeTable($tableName, $schemaName = null)
  391. {
  392. /**
  393. * Discover metadata information about this table.
  394. */
  395. $sql = "exec sp_columns @table_name = " . $this->quoteIdentifier($tableName, true);
  396. $stmt = $this->query($sql);
  397. $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
  398. $owner = 1;
  399. $table_name = 2;
  400. $column_name = 3;
  401. $type_name = 5;
  402. $precision = 6;
  403. $length = 7;
  404. $scale = 8;
  405. $nullable = 10;
  406. $column_def = 12;
  407. $column_position = 16;
  408. /**
  409. * Discover primary key column(s) for this table.
  410. */
  411. $tableOwner = $result[0][$owner];
  412. $sql = "exec sp_pkeys @table_owner = " . $tableOwner
  413. . ", @table_name = " . $this->quoteIdentifier($tableName, true);
  414. $stmt = $this->query($sql);
  415. $primaryKeysResult = $stmt->fetchAll(Zend_Db::FETCH_NUM);
  416. $primaryKeyColumn = array();
  417. // Per http://msdn.microsoft.com/en-us/library/ms189813.aspx,
  418. // results from sp_keys stored procedure are:
  419. // 0=TABLE_QUALIFIER 1=TABLE_OWNER 2=TABLE_NAME 3=COLUMN_NAME 4=KEY_SEQ 5=PK_NAME
  420. $pkey_column_name = 3;
  421. $pkey_key_seq = 4;
  422. foreach ($primaryKeysResult as $pkeysRow) {
  423. $primaryKeyColumn[$pkeysRow[$pkey_column_name]] = $pkeysRow[$pkey_key_seq];
  424. }
  425. $desc = array();
  426. $p = 1;
  427. foreach ($result as $key => $row) {
  428. $identity = false;
  429. $words = explode(' ', $row[$type_name], 2);
  430. if (isset($words[0])) {
  431. $type = $words[0];
  432. if (isset($words[1])) {
  433. $identity = (bool) preg_match('/identity/', $words[1]);
  434. }
  435. }
  436. $isPrimary = array_key_exists($row[$column_name], $primaryKeyColumn);
  437. if ($isPrimary) {
  438. $primaryPosition = $primaryKeyColumn[$row[$column_name]];
  439. } else {
  440. $primaryPosition = null;
  441. }
  442. $desc[$this->foldCase($row[$column_name])] = array(
  443. 'SCHEMA_NAME' => null, // @todo
  444. 'TABLE_NAME' => $this->foldCase($row[$table_name]),
  445. 'COLUMN_NAME' => $this->foldCase($row[$column_name]),
  446. 'COLUMN_POSITION' => (int) $row[$column_position],
  447. 'DATA_TYPE' => $type,
  448. 'DEFAULT' => $row[$column_def],
  449. 'NULLABLE' => (bool) $row[$nullable],
  450. 'LENGTH' => $row[$length],
  451. 'SCALE' => $row[$scale],
  452. 'PRECISION' => $row[$precision],
  453. 'UNSIGNED' => null, // @todo
  454. 'PRIMARY' => $isPrimary,
  455. 'PRIMARY_POSITION' => $primaryPosition,
  456. 'IDENTITY' => $identity,
  457. );
  458. }
  459. return $desc;
  460. }
  461. /**
  462. * Leave autocommit mode and begin a transaction.
  463. *
  464. * @return void
  465. * @throws Zend_Db_Adapter_Sqlsrv_Exception
  466. */
  467. protected function _beginTransaction()
  468. {
  469. if (!sqlsrv_begin_transaction($this->_connection)) {
  470. require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
  471. throw new Zend_Db_Adapter_Sqlsrv_Exception(sqlsrv_errors());
  472. }
  473. }
  474. /**
  475. * Commit a transaction and return to autocommit mode.
  476. *
  477. * @return void
  478. * @throws Zend_Db_Adapter_Sqlsrv_Exception
  479. */
  480. protected function _commit()
  481. {
  482. if (!sqlsrv_commit($this->_connection)) {
  483. require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
  484. throw new Zend_Db_Adapter_Sqlsrv_Exception(sqlsrv_errors());
  485. }
  486. }
  487. /**
  488. * Roll back a transaction and return to autocommit mode.
  489. *
  490. * @return void
  491. * @throws Zend_Db_Adapter_Sqlsrv_Exception
  492. */
  493. protected function _rollBack()
  494. {
  495. if (!sqlsrv_rollback($this->_connection)) {
  496. require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
  497. throw new Zend_Db_Adapter_Sqlsrv_Exception(sqlsrv_errors());
  498. }
  499. }
  500. /**
  501. * Set the fetch mode.
  502. *
  503. * @todo Support FETCH_CLASS and FETCH_INTO.
  504. *
  505. * @param integer $mode A fetch mode.
  506. * @return void
  507. * @throws Zend_Db_Adapter_Sqlsrv_Exception
  508. */
  509. public function setFetchMode($mode)
  510. {
  511. switch ($mode) {
  512. case Zend_Db::FETCH_NUM: // seq array
  513. case Zend_Db::FETCH_ASSOC: // assoc array
  514. case Zend_Db::FETCH_BOTH: // seq+assoc array
  515. case Zend_Db::FETCH_OBJ: // object
  516. $this->_fetchMode = $mode;
  517. break;
  518. case Zend_Db::FETCH_BOUND: // bound to PHP variable
  519. require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
  520. throw new Zend_Db_Adapter_Sqlsrv_Exception('FETCH_BOUND is not supported yet');
  521. break;
  522. default:
  523. require_once 'Zend/Db/Adapter/Sqlsrv/Exception.php';
  524. throw new Zend_Db_Adapter_Sqlsrv_Exception("Invalid fetch mode '$mode' specified");
  525. break;
  526. }
  527. }
  528. /**
  529. * Adds an adapter-specific LIMIT clause to the SELECT statement.
  530. *
  531. * @param string $sql
  532. * @param integer $count
  533. * @param integer $offset OPTIONAL
  534. * @return string
  535. * @throws Zend_Db_Adapter_Sqlsrv_Exception
  536. */
  537. public function limit($sql, $count, $offset = 0)
  538. {
  539. $count = intval($count);
  540. if ($count <= 0) {
  541. require_once 'Zend/Db/Adapter/Exception.php';
  542. throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
  543. }
  544. $offset = intval($offset);
  545. if ($offset < 0) {
  546. /** @see Zend_Db_Adapter_Exception */
  547. require_once 'Zend/Db/Adapter/Exception.php';
  548. throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
  549. }
  550. $orderby = stristr($sql, 'ORDER BY');
  551. if ($orderby !== false) {
  552. $sort = (stripos($orderby, ' desc') !== false) ? 'desc' : 'asc';
  553. $order = str_ireplace('ORDER BY', '', $orderby);
  554. $order = trim(preg_replace('/\bASC\b|\bDESC\b/i', '', $order));
  555. }
  556. $sql = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . ($count+$offset) . ' ', $sql);
  557. $sql = 'SELECT * FROM (SELECT TOP ' . $count . ' * FROM (' . $sql . ') AS inner_tbl';
  558. if ($orderby !== false) {
  559. $sql .= ' ORDER BY ' . $order . ' ';
  560. $sql .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC';
  561. }
  562. $sql .= ') AS outer_tbl';
  563. if ($orderby !== false) {
  564. $sql .= ' ORDER BY ' . $order . ' ' . $sort;
  565. }
  566. return $sql;
  567. }
  568. /**
  569. * Check if the adapter supports real SQL parameters.
  570. *
  571. * @param string $type 'positional' or 'named'
  572. * @return bool
  573. */
  574. public function supportsParameters($type)
  575. {
  576. if ($type == 'positional') {
  577. return true;
  578. }
  579. // if its 'named' or anything else
  580. return false;
  581. }
  582. /**
  583. * Retrieve server version in PHP style
  584. *
  585. * @return string
  586. */
  587. public function getServerVersion()
  588. {
  589. $this->_connect();
  590. $version = sqlsrv_client_info($this->_connection);
  591. if ($version !== false) {
  592. return $version['DriverVer'];
  593. }
  594. return null;
  595. }
  596. }