Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fetchFromSql() {
- $serverName = $this->serverName;
- $dataBase = $this->dataBase;
- $userName = $this->userName;
- $password = $this->password;
- $connectionInfo = array("Database" => $dataBase, "UID" => $userName, "PWD" => $password);
- $conn = sqlsrv_connect($serverName, $connectionInfo);
- if ($conn === false) {
- die(print_r(sqlsrv_errors(), true));
- }
- $sqlQuery = "SELECT * FROM(SELECT [name],[date],[status],row_number() OVER (PARTITION BY [name] ORDER BY [date] DESC) AS rownum
- FROM [script_monitoring].[dbo].[script_status]) [script_status] where rownum <= 10";
- $params = array();
- $options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
- $stmt = sqlsrv_query($conn, $sqlQuery, $params, $options);
- if (sqlsrv_fetch($stmt) === false) {
- die(print_r(sqlsrv_errors(), true));
- }
- return array($stmt, $conn);
- }
- function convertFromSql() {
- $const = new ConnectionData();
- $handler = new DataHandler($const::SERVERNAME, $const::DATABASE, $const::USER, $const::PASS);
- $stmt = $handler->fetchFromSql();
- $arData = array();
- $arNames = array();
- $n = 0;
- while ($row = sqlsrv_fetch_array($stmt[0], SQLSRV_FETCH_NUMERIC)) {
- $arData[$n][0] = $row[0];
- $arData[$n][1] = date_format($row[1], "Y-m-d H:i:s");
- $arData[$n][2] = $row[2];
- $arNames[$n] = $row[0];
- $n++;
- }
- sqlsrv_free_stmt($stmt[0]);
- sqlsrv_close($stmt[1]);
- $arUniqueNames = array_unique($arNames);
- return array($arData, $arUniqueNames);
- }
- name date status rownum
- Awayalogs 2017-02-28 23:59:19.327 1 1
- Awayalogs 2017-02-27 23:59:14.423 1 2
- Awayalogs 2017-02-21 23:59:15.490 1 3
- Awayalogs 2017-02-20 23:59:16.350 1 4
- Awayalogs 2017-02-19 23:59:12.927 1 5
- Awayalogs 2017-02-18 23:59:17.993 1 6
- Awayalogs 2017-02-17 23:59:12.600 1 7
- Awayalogs 2017-02-16 23:59:20.817 1 8
- Awayalogs 2017-02-15 23:59:13.690 1 9
- Awayalogs 2017-02-14 23:59:14.040 1 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement