Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. function fetchFromSql() {
  2. $serverName = $this->serverName;
  3. $dataBase = $this->dataBase;
  4. $userName = $this->userName;
  5. $password = $this->password;
  6.  
  7. $connectionInfo = array("Database" => $dataBase, "UID" => $userName, "PWD" => $password);
  8. $conn = sqlsrv_connect($serverName, $connectionInfo);
  9.  
  10. if ($conn === false) {
  11. die(print_r(sqlsrv_errors(), true));
  12. }
  13.  
  14. $sqlQuery = "SELECT * FROM(SELECT [name],[date],[status],row_number() OVER (PARTITION BY [name] ORDER BY [date] DESC) AS rownum
  15. FROM [script_monitoring].[dbo].[script_status]) [script_status] where rownum <= 10";
  16.  
  17. $params = array();
  18. $options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
  19.  
  20. $stmt = sqlsrv_query($conn, $sqlQuery, $params, $options);
  21.  
  22. if (sqlsrv_fetch($stmt) === false) {
  23. die(print_r(sqlsrv_errors(), true));
  24. }
  25.  
  26. return array($stmt, $conn);
  27. }
  28.  
  29. function convertFromSql() {
  30. $const = new ConnectionData();
  31. $handler = new DataHandler($const::SERVERNAME, $const::DATABASE, $const::USER, $const::PASS);
  32. $stmt = $handler->fetchFromSql();
  33.  
  34. $arData = array();
  35. $arNames = array();
  36. $n = 0;
  37.  
  38. while ($row = sqlsrv_fetch_array($stmt[0], SQLSRV_FETCH_NUMERIC)) {
  39. $arData[$n][0] = $row[0];
  40. $arData[$n][1] = date_format($row[1], "Y-m-d H:i:s");
  41. $arData[$n][2] = $row[2];
  42. $arNames[$n] = $row[0];
  43. $n++;
  44. }
  45. sqlsrv_free_stmt($stmt[0]);
  46. sqlsrv_close($stmt[1]);
  47.  
  48. $arUniqueNames = array_unique($arNames);
  49.  
  50. return array($arData, $arUniqueNames);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement