connection = \mssql_connect($hostname, $username, $password)) { throw new \Phacil\Framework\Exception('Error: Could not make a database connection using ' . $username . '@' . $hostname); } if (!\mssql_select_db($database, $this->connection)) { throw new \Phacil\Framework\Exception('Error: Could not connect to database ' . $database); } \mssql_query("SET NAMES 'utf8'", $this->connection); \mssql_query("SET CHARACTER SET utf8", $this->connection); \mssql_query("SET CHARACTER_SET_CONNECTION=utf8", $this->connection); } /** @inheritdoc */ public function query($sql) { $resource = \mssql_query($sql, $this->connection); if ($resource) { if (is_resource($resource)) { $i = 0; $data = array(); while ($result = \mssql_fetch_assoc($resource)) { $data[$i] = $result; $i++; } \mssql_free_result($resource); /** @var \Phacil\Framework\Databases\Object\ResultInterface */ $query = \Phacil\Framework\Registry::getInstance()->create(\Phacil\Framework\Databases\Object\ResultInterface::class, [$data]); $query->setNumRows($i); unset($data); return $query; } else { return true; } } else { throw new \Phacil\Framework\Exception('Error: ' . mssql_get_last_message($this->connection) . '
' . $sql); } } /** {@inheritdoc} */ public function escape($value) { return \mssql_real_escape_string($value, $this->connection); } /** {@inheritdoc} */ public function countAffected() { return \mssql_rows_affected($this->connection); } /** {@inheritdoc} */ public function getLastId() { $last_id = false; $resource = \mssql_query("SELECT @@identity AS id", $this->connection); if ($row = mssql_fetch_row($resource)) { $last_id = trim($row[0]); } \mssql_free_result($resource); return $last_id; } /** @inheritdoc */ function isConnected() { return !empty($this->connection); } /** @inheritdoc */ public function execute($sql, array $params = []) { $sql = str_replace(array_keys($params), array_values($params), $sql); return $this->query($sql); } /** * * {@inheritdoc} */ public function getDBType() { return self::DB_TYPE; } /** * * {@inheritdoc} */ public function getDBTypeId() { return self::DB_TYPE_ID; } }