{"action":"created","issue":{"url":"https://api.github.com/repos/padams/Open-Web-Analytics/issues/84","labels_url":"https://api.github.com/repos/padams/Open-Web-Analytics/issues/84/labels{/name}","comments_url":"https://api.github.com/repos/padams/Open-Web-Analytics/issues/84/comments","events_url":"https://api.github.com/repos/padams/Open-Web-Analytics/issues/84/events","html_url":"https://github.com/padams/Open-Web-Analytics/issues/84","id":84076985,"number":84,"title":"Unable to install OWA 1.5.7 with SQL Server 2008","user":{"login":"TomBrady","id":12716796,"avatar_url":"https://avatars.githubusercontent.com/u/12716796?v=3","gravatar_id":"","url":"https://api.github.com/users/TomBrady","html_url":"https://github.com/TomBrady","followers_url":"https://api.github.com/users/TomBrady/followers","following_url":"https://api.github.com/users/TomBrady/following{/other_user}","gists_url":"https://api.github.com/users/TomBrady/gists{/gist_id}","starred_url":"https://api.github.com/users/TomBrady/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomBrady/subscriptions","organizations_url":"https://api.github.com/users/TomBrady/orgs","repos_url":"https://api.github.com/users/TomBrady/repos","events_url":"https://api.github.com/users/TomBrady/events{/privacy}","received_events_url":"https://api.github.com/users/TomBrady/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-02T15:39:30Z","updated_at":"2015-06-02T15:41:07Z","closed_at":null,"body":"Trying to upgrade our install to OWA 1.5.7 on a Windows IIS hitting against SQL Server 2008.\r\n\r\nUsing PHP 5.3 also (same set up as older OWA installation).\r\n\r\nI have a brand new empty database for testing & am getting Entity Installation failed errors which appears to be a SQL issue, but the not sure how this can be if it is the same environment as the original installation?\r\n\r\nI’ve enclosed the DB plug-in being used for SQL Server that was originally used for the previous installation.\r\n\r\nSomewhat a newbie at PHP which is not helping!   ;-}\r\n\r\n--------------------------------------------------------------------------------------------------------------------------\r\n\r\n\r\n\r\n06:48:41 05/28/15 19388 [debug] Query: CREATE TABLE IF NOT EXISTS owa_commerce_transaction_fact (id BIGINT PRIMARY KEY, visitor_id BIGINT, session_id BIGINT, INDEX (session_id), site_id VARCHAR(255), INDEX (site_id), referer_id BIGINT, ua_id BIGINT, host_id BIGINT, os_id BIGINT, location_id BIGINT, referring_search_term_id BIGINT, timestamp INT, yyyymmdd INT, INDEX (yyyymmdd), year INT, month INT, day TINYINT(2), dayofweek VARCHAR(10), dayofyear INT, weekofyear INT, last_req BIGINT, ip_address VARCHAR(255), is_new_visitor TINYINT(1), is_repeat_visitor TINYINT(1), language VARCHAR(255), days_since_prior_session INT, days_since_first_session INT, num_prior_sessions INT, medium VARCHAR(255), source_id BIGINT, ad_id BIGINT, campaign_id BIGINT, user_name VARCHAR(255), cv1_name VARCHAR(255), cv1_value VARCHAR(255), cv2_name VARCHAR(255), cv2_value VARCHAR(255), cv3_name VARCHAR(255), cv3_value VARCHAR(255), cv4_name VARCHAR(255), cv4_value VARCHAR(255), cv5_name VARCHAR(255), cv5_value VARCHAR(255), document_id BIGINT, order_id VARCHAR(255), INDEX (order_id), order_source VARCHAR(255), gateway VARCHAR(255), total_revenue BIGINT, tax_revenue BIGINT, shipping_revenue BIGINT) ENGINE = INNODB CHARACTER SET = utf8\r\n06:48:41 05/28/15 19388 [debug] A SQL Server error occured. Error: (156) [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near the keyword 'IF'.. Query: CREATE TABLE IF NOT EXISTS owa_commerce_transaction_fact (id BIGINT PRIMARY KEY, visitor_id BIGINT, session_id BIGINT, INDEX (session_id), site_id VARCHAR(255), INDEX (site_id), referer_id BIGINT, ua_id BIGINT, host_id BIGINT, os_id BIGINT, location_id BIGINT, referring_search_term_id BIGINT, timestamp INT, yyyymmdd INT, INDEX (yyyymmdd), year INT, month INT, day TINYINT(2), dayofweek VARCHAR(10), dayofyear INT, weekofyear INT, last_req BIGINT, ip_address VARCHAR(255), is_new_visitor TINYINT(1), is_repeat_visitor TINYINT(1), language VARCHAR(255), days_since_prior_session INT, days_since_first_session INT, num_prior_sessions INT, medium VARCHAR(255), source_id BIGINT, ad_id BIGINT, campaign_id BIGINT, user_name VARCHAR(255), cv1_name VARCHAR(255), cv1_value VARCHAR(255), cv2_name VARCHAR(255), cv2_value VARCHAR(255), cv3_name VARCHAR(255), cv3_value VARCHAR(255), cv4_name VARCHAR(255), cv4_value VARCHAR(255), cv5_name VARCHAR(255), cv5_value VARCHAR(255), document_id BIGINT, order_id VARCHAR(255), INDEX (order_id), order_source VARCHAR(255), gateway VARCHAR(255), total_revenue BIGINT, tax_revenue BIGINT, shipping_revenue BIGINT) ENGINE = INNODB CHARACTER SET = utf8\r\n06:48:41 05/28/15 19388 [debug] A SQL Server error occured. Error: (102) [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'owa_commerce_transaction_fact'.. Query: CREATE TABLE IF NOT EXISTS owa_commerce_transaction_fact (id BIGINT PRIMARY KEY, visitor_id BIGINT, session_id BIGINT, INDEX (session_id), site_id VARCHAR(255), INDEX (site_id), referer_id BIGINT, ua_id BIGINT, host_id BIGINT, os_id BIGINT, location_id BIGINT, referring_search_term_id BIGINT, timestamp INT, yyyymmdd INT, INDEX (yyyymmdd), year INT, month INT, day TINYINT(2), dayofweek VARCHAR(10), dayofyear INT, weekofyear INT, last_req BIGINT, ip_address VARCHAR(255), is_new_visitor TINYINT(1), is_repeat_visitor TINYINT(1), language VARCHAR(255), days_since_prior_session INT, days_since_first_session INT, num_prior_sessions INT, medium VARCHAR(255), source_id BIGINT, ad_id BIGINT, campaign_id BIGINT, user_name VARCHAR(255), cv1_name VARCHAR(255), cv1_value VARCHAR(255), cv2_name VARCHAR(255), cv2_value VARCHAR(255), cv3_name VARCHAR(255), cv3_value VARCHAR(255), cv4_name VARCHAR(255), cv4_value VARCHAR(255), cv5_name VARCHAR(255), cv5_value VARCHAR(255), document_id BIGINT, order_id VARCHAR(255), INDEX (order_id), order_source VARCHAR(255), gateway VARCHAR(255), total_revenue BIGINT, tax_revenue BIGINT, shipping_revenue BIGINT) ENGINE = INNODB CHARACTER SET = utf8\r\n06:48:41 05/28/15 19388 [notice] owa_commerce_transaction_fact Table Creation Failed.\r\n06:48:41 05/28/15 19388 [notice] Entity Installation Failed.\r\n06:48:41 05/28/15 19388 [debug] Query: CREATE TABLE IF NOT EXISTS owa_commerce_line_item_fact (id BIGINT PRIMARY KEY, visitor_id BIGINT, session_id BIGINT, INDEX (session_id), site_id VARCHAR(255), INDEX (site_id), referer_id BIGINT, ua_id BIGINT, host_id BIGINT, os_id BIGINT, location_id BIGINT, referring_search_term_id BIGINT, timestamp INT, yyyymmdd INT, INDEX (yyyymmdd), year INT, month INT, day TINYINT(2), dayofweek VARCHAR(10), dayofyear INT, weekofyear INT, last_req BIGINT, ip_address VARCHAR(255), is_new_visitor TINYINT(1), is_repeat_visitor TINYINT(1), language VARCHAR(255), days_since_prior_session INT, days_since_first_session INT, num_prior_sessions INT, medium VARCHAR(255), source_id BIGINT, ad_id BIGINT, campaign_id BIGINT, user_name VARCHAR(255), cv1_name VARCHAR(255), cv1_value VARCHAR(255), cv2_name VARCHAR(255), cv2_value VARCHAR(255), cv3_name VARCHAR(255), cv3_value VARCHAR(255), cv4_name VARCHAR(255), cv4_value VARCHAR(255), cv5_name VARCHAR(255), cv5_value VARCHAR(255), document_id BIGINT, order_id VARCHAR(255), INDEX (order_id), sku VARCHAR(255), product_name VARCHAR(255), category VARCHAR(255), unit_price BIGINT, quantity INT, item_revenue BIGINT) ENGINE = INNODB CHARACTER SET = utf8\r\n06:48:41 05/28/15 19388 [debug] A SQL Server error occured. Error: (156) [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near the keyword 'IF'.. Query: CREATE TABLE IF NOT EXISTS owa_commerce_line_item_fact (id BIGINT PRIMARY KEY, visitor_id BIGINT, session_id BIGINT, INDEX (session_id), site_id VARCHAR(255), INDEX (site_id), referer_id BIGINT, ua_id BIGINT, host_id BIGINT, os_id BIGINT, location_id BIGINT, referring_search_term_id BIGINT, timestamp INT, yyyymmdd INT, INDEX (yyyymmdd), year INT, month INT, day TINYINT(2), dayofweek VARCHAR(10), dayofyear INT, weekofyear INT, last_req BIGINT, ip_address VARCHAR(255), is_new_visitor TINYINT(1), is_repeat_visitor TINYINT(1), language VARCHAR(255), days_since_prior_session INT, days_since_first_session INT, num_prior_sessions INT, medium VARCHAR(255), source_id BIGINT, ad_id BIGINT, campaign_id BIGINT, user_name VARCHAR(255), cv1_name VARCHAR(255), cv1_value VARCHAR(255), cv2_name VARCHAR(255), cv2_value VARCHAR(255), cv3_name VARCHAR(255), cv3_value VARCHAR(255), cv4_name VARCHAR(255), cv4_value VARCHAR(255), cv5_name VARCHAR(255), cv5_value VARCHAR(255), document_id BIGINT, order_id VARCHAR(255), INDEX (order_id), sku VARCHAR(255), product_name VARCHAR(255), category VARCHAR(255), unit_price BIGINT, quantity INT, item_revenue BIGINT) ENGINE = INNODB CHARACTER SET = utf8\r\n06:48:41 05/28/15 19388 [debug] A SQL Server error occured. Error: (102) [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'owa_commerce_line_item_fact'.. Query: CREATE TABLE IF NOT EXISTS owa_commerce_line_item_fact (id BIGINT PRIMARY KEY, visitor_id BIGINT, session_id BIGINT, INDEX (session_id), site_id VARCHAR(255), INDEX (site_id), referer_id BIGINT, ua_id BIGINT, host_id BIGINT, os_id BIGINT, location_id BIGINT, referring_search_term_id BIGINT, timestamp INT, yyyymmdd INT, INDEX (yyyymmdd), year INT, month INT, day TINYINT(2), dayofweek VARCHAR(10), dayofyear INT, weekofyear INT, last_req BIGINT, ip_address VARCHAR(255), is_new_visitor TINYINT(1), is_repeat_visitor TINYINT(1), language VARCHAR(255), days_since_prior_session INT, days_since_first_session INT, num_prior_sessions INT, medium VARCHAR(255), source_id BIGINT, ad_id BIGINT, campaign_id BIGINT, user_name VARCHAR(255), cv1_name VARCHAR(255), cv1_value VARCHAR(255), cv2_name VARCHAR(255), cv2_value VARCHAR(255), cv3_name VARCHAR(255), cv3_value VARCHAR(255), cv4_name VARCHAR(255), cv4_value VARCHAR(255), cv5_name VARCHAR(255), cv5_value VARCHAR(255), document_id BIGINT, order_id VARCHAR(255), INDEX (order_id), sku VARCHAR(255), product_name VARCHAR(255), category VARCHAR(255), unit_price BIGINT, quantity INT, item_revenue BIGINT) ENGINE = INNODB CHARACTER SET = utf8\r\n06:48:41 05/28/15 19388 [notice] owa_commerce_line_item_fact Table Creation Failed.\r\n06:48:41 05/28/15 19388 [notice] Entity Installation Failed.\r\n06:48:41 05/28/15 19388 [debug] Query: CREATE TABLE IF NOT EXISTS owa_queue_item (id BIGINT PRIMARY KEY, event_type VARCHAR(255), priority INT, status VARCHAR(255), event BLOB, insertion_datestamp TIMESTAMP, insertion_timestamp INT, handled_timestamp INT, last_attempt_timestamp INT, not_before_timestamp INT, failed_attempt_count INT, is_assigned TINYINT(1), last_error_msg VARCHAR(255), handled_by VARCHAR(255), handler_duration INT) ENGINE = INNODB CHARACTER SET = utf8\r\n06:48:41 05/28/15 19388 [debug] A SQL Server error occured. Error: (156) [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near the keyword 'IF'.. Query: CREATE TABLE IF NOT EXISTS owa_queue_item (id BIGINT PRIMARY KEY, event_type VARCHAR(255), priority INT, status VARCHAR(255), event BLOB, insertion_datestamp TIMESTAMP, insertion_timestamp INT, handled_timestamp INT, last_attempt_timestamp INT, not_before_timestamp INT, failed_attempt_count INT, is_assigned TINYINT(1), last_error_msg VARCHAR(255), handled_by VARCHAR(255), handler_duration INT) ENGINE = INNODB CHARACTER SET = utf8\r\n06:48:41 05/28/15 19388 [debug] A SQL Server error occured. Error: (102) [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'owa_queue_item'.. Query: CREATE TABLE IF NOT EXISTS owa_queue_item (id BIGINT PRIMARY KEY, event_type VARCHAR(255), priority INT, status VARCHAR(255), event BLOB, insertion_datestamp TIMESTAMP, insertion_timestamp INT, handled_timestamp INT, last_attempt_timestamp INT, not_before_timestamp INT, failed_attempt_count INT, is_assigned TINYINT(1), last_error_msg VARCHAR(255), handled_by VARCHAR(255), handler_duration INT) ENGINE = INNODB CHARACTER SET = utf8\r\n06:48:41 05/28/15 19388 [notice] owa_queue_item Table Creation Failed.\r\n06:48:41 05/28/15 19388 [notice] Entity Installation Failed.\r\n06:48:41 05/28/15 19388 [debug] Query: CREATE TABLE IF NOT EXISTS owa_site_user (site_id BIGINT, user_id INT) ENGINE = INNODB CHARACTER SET = utf8\r\n06:48:41 05/28/15 19388 [debug] A SQL Server error occured. Error: (156) [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near the keyword 'IF'.. Query: CREATE TABLE IF NOT EXISTS owa_site_user (site_id BIGINT, user_id INT) ENGINE = INNODB CHARACTER SET = utf8\r\n06:48:41 05/28/15 19388 [debug] A SQL Server error occured. Error: (102) [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'owa_site_user'.. Query: CREATE TABLE IF NOT EXISTS owa_site_user (site_id BIGINT, user_id INT) ENGINE = INNODB CHARACTER SET = utf8\r\n06:48:41 05/28/15 19388 [notice] owa_site_user Table Creation Failed.\r\n06:48:41 05/28/15 19388 [notice] Entity Installation Failed.\r\n06:48:41 05/28/15 19388 [notice] Installation failed.\r\n06:48:41 05/28/15 19388 [debug] Assembling view: owa_installView\r\n06:48:41 05/28/15 19388 [debug] Total session time: 0.40062117576599\r\n06:48:41 05/28/15 19388 [debug] goodbye from OWA\r\n"},"comment":{"url":"https://api.github.com/repos/padams/Open-Web-Analytics/issues/comments/107994654","html_url":"https://github.com/padams/Open-Web-Analytics/issues/84#issuecomment-107994654","issue_url":"https://api.github.com/repos/padams/Open-Web-Analytics/issues/84","id":107994654,"user":{"login":"TomBrady","id":12716796,"avatar_url":"https://avatars.githubusercontent.com/u/12716796?v=3","gravatar_id":"","url":"https://api.github.com/users/TomBrady","html_url":"https://github.com/TomBrady","followers_url":"https://api.github.com/users/TomBrady/followers","following_url":"https://api.github.com/users/TomBrady/following{/other_user}","gists_url":"https://api.github.com/users/TomBrady/gists{/gist_id}","starred_url":"https://api.github.com/users/TomBrady/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomBrady/subscriptions","organizations_url":"https://api.github.com/users/TomBrady/orgs","repos_url":"https://api.github.com/users/TomBrady/repos","events_url":"https://api.github.com/users/TomBrady/events{/privacy}","received_events_url":"https://api.github.com/users/TomBrady/received_events","type":"User","site_admin":false},"created_at":"2015-06-02T15:41:06Z","updated_at":"2015-06-02T15:41:06Z","body":"owa_db_sqlsrv.php (from Git repository)\r\n\r\n<?php\r\n\r\n//\r\n// Open Web Analytics - An Open Source Web Analytics Framework\r\n//\r\n// Copyright 2006 Peter Adams. All rights reserved.\r\n//\r\n// Licensed under GPL v2.0 http://www.gnu.org/copyleft/gpl.html\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n//\r\n// $Id$\r\n//\r\n\r\n\r\ndefine('OWA_DTD_BIGINT', 'BIGINT'); \r\ndefine('OWA_DTD_INT', 'INT');\r\ndefine('OWA_DTD_TINYINT', 'TINYINT(1)');\r\ndefine('OWA_DTD_TINYINT2', 'TINYINT(2)');\r\ndefine('OWA_DTD_TINYINT4', 'TINYINT(4)');\r\ndefine('OWA_DTD_SERIAL', 'IDENTITY');\r\ndefine('OWA_DTD_PRIMARY_KEY', 'PRIMARY KEY');\r\ndefine('OWA_DTD_VARCHAR10', 'VARCHAR(10)');\r\ndefine('OWA_DTD_VARCHAR255', 'VARCHAR(255)');\r\ndefine('OWA_DTD_VARCHAR', 'VARCHAR(%s)');\r\ndefine('OWA_DTD_TEXT', 'TEXT');\r\ndefine('OWA_DTD_BOOLEAN', 'TINYINT(1)');\r\ndefine('OWA_DTD_TIMESTAMP', 'TIMESTAMP');\r\ndefine('OWA_DTD_BLOB', 'BLOB');\r\ndefine('OWA_DTD_INDEX', 'KEY');\r\ndefine('OWA_DTD_AUTO_INCREMENT', 'AUTO_INCREMENT');\r\ndefine('OWA_DTD_NOT_NULL', 'NOT NULL');\r\ndefine('OWA_DTD_UNIQUE', 'PRIMARY KEY(%s)');\r\ndefine('OWA_SQL_ADD_COLUMN', 'ALTER TABLE %s ADD %s %s');   \r\ndefine('OWA_SQL_DROP_COLUMN', 'ALTER TABLE %s DROP %s');\r\ndefine('OWA_SQL_RENAME_COLUMN', 'ALTER TABLE %s CHANGE %s %s %s'); \r\ndefine('OWA_SQL_MODIFY_COLUMN', 'ALTER TABLE %s MODIFY %s %s'); \r\ndefine('OWA_SQL_RENAME_TABLE', 'ALTER TABLE %s RENAME %s'); \r\ndefine('OWA_SQL_CREATE_TABLE', 'CREATE TABLE IF NOT EXISTS %s (%s) %s'); \r\ndefine('OWA_SQL_DROP_TABLE', 'DROP TABLE IF EXISTS %s');  \r\ndefine('OWA_SQL_INSERT_ROW', 'INSERT into %s (%s) VALUES (%s)');\r\ndefine('OWA_SQL_UPDATE_ROW', 'UPDATE %s SET %s %s');\r\ndefine('OWA_SQL_DELETE_ROW', \"DELETE from %s %s\");\r\ndefine('OWA_SQL_CREATE_INDEX', 'CREATE INDEX %s ON %s (%s)');\r\ndefine('OWA_SQL_DROP_INDEX', 'DROP INDEX %s ON %s');\r\ndefine('OWA_SQL_INDEX', 'INDEX (%s)');\r\ndefine('OWA_SQL_BEGIN_TRANSACTION', 'BEGIN TRANS');\r\ndefine('OWA_SQL_END_TRANSACTION', 'COMMIT TRANS');\r\ndefine('OWA_DTD_TABLE_TYPE', 'ENGINE = %s');\r\ndefine('OWA_DTD_TABLE_TYPE_DEFAULT', 'INNODB');\r\ndefine('OWA_DTD_TABLE_TYPE_DISK', 'INNODB');\r\ndefine('OWA_DTD_TABLE_TYPE_MEMORY', 'MEMORY');\r\ndefine('OWA_SQL_ALTER_TABLE_TYPE', 'ALTER TABLE %s ENGINE = %s');\r\ndefine('OWA_SQL_JOIN_LEFT_OUTER', 'LEFT OUTER JOIN');\r\ndefine('OWA_SQL_JOIN_LEFT_INNER', 'LEFT INNER JOIN');\r\ndefine('OWA_SQL_JOIN_RIGHT_OUTER', 'RIGHT OUTER JOIN');\r\ndefine('OWA_SQL_JOIN_RIGHT_INNER', 'RIGHT INNER JOIN');\r\ndefine('OWA_SQL_JOIN', 'JOIN');\r\ndefine('OWA_SQL_DESCENDING', 'DESC');\r\ndefine('OWA_SQL_ASCENDING', 'ASC');\r\ndefine('OWA_SQL_REGEXP', 'REGEXP');\r\ndefine('OWA_SQL_NOTREGEXP', 'NOT REGEXP');\r\ndefine('OWA_SQL_LIKE', 'LIKE');\r\ndefine('OWA_SQL_ADD_INDEX', 'ALTER TABLE %s ADD INDEX (%s) %s');\r\ndefine('OWA_SQL_COUNT', 'COUNT(%s)');\r\ndefine('OWA_SQL_SUM', 'SUM(%s)');\r\ndefine('OWA_SQL_ROUND', 'ROUND(%s,0)');\r\ndefine('OWA_SQL_AVERAGE', 'AVG(%s)');\r\ndefine('OWA_SQL_DISTINCT', 'DISTINCT %s');\r\ndefine('OWA_SQL_DIVISION', '(%s / %s)');\r\ndefine('OWA_DTD_CHARACTER_ENCODING_UTF8', 'utf8');\r\ndefine('OWA_DTD_TABLE_CHARACTER_ENCODING', 'CHARACTER SET = %s');\r\n\r\n\r\n/**\r\n * MySQL Data Access Class\r\n * \r\n * @author      Peter Adams <peter@openwebanalytics.com>\r\n * @copyright   Copyright &copy; 2006 Peter Adams <peter@openwebanalytics.com>\r\n * @license     http://www.gnu.org/copyleft/gpl.html GPL v2.0\r\n * @category    owa\r\n * @package     owa\r\n * @version\t\t$Revision$\t      \r\n * @since\t\towa 1.0.0\r\n */\r\nclass owa_db_sqlsrv extends owa_db {\r\n\r\n\t\r\n\tfunction connect() {\r\n\t\r\n\t\tif (!$this->connection) {\r\n\t\t\t\r\n\t\t\tif ($this->getConnectionParam('persistant')) {\r\n\t\t\t\t\r\n\t\t\t\t$this->connection = sqlsrv_connect(\r\n\t\t\t\t\t$this->getConnectionParam('host'),\r\n\t\t\t\t\tarray(\"Database\"=>$this->getConnectionParam('name'), \r\n\t\t\t\t\t\"UID\"=>$this->getConnectionParam('user'),\r\n\t\t\t\t\t\"PWD\"=>$this->getConnectionParam('password'))\r\n\t    \t\t);\r\n\t    \t\t\r\n\t\t\t} else {\r\n\t\t\t\t\r\n\t\t\t\t$this->connection = sqlsrv_connect(\r\n\t\t\t\t\t$this->getConnectionParam('host'),\r\n\t\t\t\t\tarray(\"Database\"=>$this->getConnectionParam('name'), \r\n\t\t\t\t\t\"UID\"=>$this->getConnectionParam('user'),\r\n\t\t\t\t\t\"PWD\"=>$this->getConnectionParam('password'))\r\n\t    \t\t);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t//$this->database_selection = mysql_select_db($this->getConnectionParam('name'), $this->connection);\r\n\t\t\t//\r\n\t\t\t//if (function_exists('mysql_set_charset')) {\r\n\t\t\t//\tmysql_set_charset('utf8',$this->connection);\r\n\t\t\t//} else {\r\n\t\t\t//\t$this->query(\"SET NAMES 'utf8'\");\r\n\t\t\t//}\r\n\t\t\t\r\n\t\t}\r\n\t\t\t\r\n\t\t\t\r\n\t\tif (!$this->connection) {\r\n\t\t\t$this->e->alert('Could not connect to database.');\r\n\t\t\tif( ($errors = sqlsrv_errors() ) != null) {\r\n\t\t\t\tforeach($errors as $error) {\r\n\t\t\t\t\t$this->e->debug(sprintf('A SQL Server error occured. Error: (%s) %s.',\r\n\t\t\t\t\t$error[ 'code'],\r\n\t\t\t\t\t$error[ 'message']));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t$this->connection_status = false;\r\n\t\t\treturn false;\r\n\t\t} else {\r\n\t\t\t$this->connection_status = true;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\t/**\r\n\t * Database Query\r\n\t *\r\n\t * @param \tstring $sql\r\n\t * @access \tpublic\r\n\t * \r\n\t */\r\n\tfunction query($sql) {\r\n  \r\n  \t\tif ($this->connection_status == false):\r\n  \t\towa_coreAPI::profile($this, __FUNCTION__, __LINE__);\r\n  \t\t\t$this->connect();\r\n  \t\towa_coreAPI::profile($this, __FUNCTION__, __LINE__);\r\n  \t\tendif;\r\n  \r\n  \t\towa_coreAPI::profile($this, __FUNCTION__, __LINE__);\r\n\t\t$this->e->debug(sprintf('Query: %s', $sql));\r\n\t\t\r\n\t\t$this->result = '';\r\n\t\t$this->new_result = '';\t\r\n\t\t\r\n\t\tif (!empty($this->new_result)):\r\n\t\t\tsqlsrv_free_stmt($this->new_result);\r\n\t\tendif;\r\n\t\towa_coreAPI::profile($this, __FUNCTION__, __LINE__, $sql);\r\n\t\t$result = @sqlsrv_query($this->connection, $sql);\r\n\t\t\r\n\t\towa_coreAPI::profile($this, __FUNCTION__, __LINE__);\t\t\t\r\n\t\t// Log Errors\r\n\t\t if( ($errors = sqlsrv_errors() ) != null) {\r\n\t\t\tforeach($errors as $error) {\r\n\t\t\t\t$this->e->debug(sprintf('A SQL Server error occured. Error: (%s) %s. Query: %s',\r\n\t\t\t\t$error[ 'code'],\r\n\t\t\t\t$error[ 'message'],\r\n\t\t\t\t$sql));\r\n\t\t\t}\r\n\t\t}\t\t\r\n\t\towa_coreAPI::profile($this, __FUNCTION__, __LINE__);\r\n\t\t$this->new_result = $result;\r\n\t\t\r\n\t\treturn $this->new_result;\r\n\t\t\r\n\t}\r\n\t\r\n\tfunction close() {\r\n\t\t\r\n\t\t@sqlsrv_close($this->connection);\r\n\t\treturn;\r\n\t\t\r\n\t}\r\n\t\r\n\t/**\r\n\t * Fetch result set array\r\n\t *\r\n\t * @param \tstring $sql\r\n\t * @return \tarray\r\n\t * @access  public\r\n\t */\r\n\tfunction get_results($sql) {\r\n\t\r\n\t\tif ($sql):\r\n\t\t\t$this->query($sql);\r\n\t\tendif;\r\n\t\r\n\t\t$num_rows = 0;\r\n\t\t\r\n\t\twhile ( $row = @sqlsrv_fetch_array($this->new_result,SQLSRV_FETCH_ASSOC) ) {\r\n\t\t\t$this->result[$num_rows] = $row;\r\n\t\t\t$num_rows++;\r\n\t\t}\r\n\t\t\r\n\t\tif ($this->result):\r\n\t\t\t\t\t\r\n\t\t\treturn $this->result;\r\n\t\t\t\r\n\t\telse:\r\n\t\t\treturn null;\r\n\t\tendif;\r\n\t}\r\n\t\r\n\t/**\r\n\t * Fetch Single Row\r\n\t *\r\n\t * @param string $sql\r\n\t * @return array\r\n\t */\r\n\tfunction get_row($sql) {\r\n\t\t\r\n\t\t$this->query($sql);\r\n\t\t\r\n\t\t//print_r($this->result);\r\n\t\t$row = @sqlsrv_fetch_array($this->new_result,SQLSRV_FETCH_ASSOC);\r\n\t\t\r\n\t\treturn $row;\r\n\t}\r\n\t\r\n\t/**\r\n\t * Prepares and escapes string\r\n\t *\r\n\t * @param string $string\r\n\t * @return string\r\n\t */\r\n\tfunction prepare($string) {\r\n\t\t\r\n\t\tif ($this->connection_status == false):\r\n  \t\t\t$this->connect();\r\n  \t\tendif;\r\n\t\t\r\n\t\t$pattern = \"/'/\"; \r\n\t\t$replacement = \"''\"; \r\n\t\t\r\n\t\treturn preg_replace($pattern, $replacement, $string);\r\n\t\t\r\n\t\t\r\n\t}\r\n\t\r\n\tfunction getAffectedRows() {\r\n\t\t\r\n\t\treturn sqlsrv_rows_affected($this->new_result);\r\n\t}\r\n}\r\n\r\n?>\r\n"}}