conn = @sqlsrv_connect($server, array('UID' => $user, 'PWD' => $pass, 'Database' => $dbname, 'LoginTimeout' => 10)); if ($this->conn === false) { $this->error_log[] = sqlsrv_errors(); throw new Exception(($this->error_log[0][0]["message"] ?? '')); } } //query source function query($sql, $params = null) { $stmt = sqlsrv_query($this->conn, $sql, $params); $this->sql_log[] = $sql; if ($stmt === false) { $this->error_log[] = sqlsrv_errors(); throw new Exception(($this->error_log[0][0]["message"] ?? '')); } else { $this->query_id = $stmt; $this->num_rows = $this->affectedRows(); while ($row = @sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $data[] = $row; } if (isset($data)) { return $data; } } } // $DB->count(select count(*) from users) function count($sql) { $count = $this->fetch_one($sql); return $count[""]; } function affectedRows() { return ($this->query_id) ? @sqlsrv_num_rows($this->query_id) : false; } //$DB->fetch_all("SELECT * FROM table WHERE name= ?", array("name")); function fetch_all($sql, $params = null) { $stmt = sqlsrv_query($this->conn, $sql, $params); if ($stmt === false) { throw new Exception(($this->error_log[0][0]["message"] ?? '')); } else { $data = array(); while ($row = @sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $data[] = $row; } return $data; } } // $DB->fetch_one(select * from users) function fetch_one($sql, $params = null) { $stmt = sqlsrv_query($this->conn, $sql, $params); if ($stmt === false) { throw new Exception(($this->error_log[0][0]["message"] ?? '')); } else { return sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC); } } }