Deprecated PHP 5.6.
- Removed mysql extension for database
This commit is contained in:
parent
8296f6a00b
commit
c2ac27d637
|
@ -3,7 +3,6 @@ language: php
|
|||
php:
|
||||
- 7.1
|
||||
- 7
|
||||
- 5.6
|
||||
|
||||
script:
|
||||
- php vendor/bin/phpunit -v -c tests/phpunit.xml --coverage-text
|
||||
|
|
|
@ -1,515 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Logger;
|
||||
|
||||
/**
|
||||
* MS SQL Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_mssql_driver extends FW_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'mssql';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('NEWID()', 'RAND(%d)');
|
||||
|
||||
/**
|
||||
* Quoted identifier flag
|
||||
*
|
||||
* Whether to use SQL-92 standard quoted identifier
|
||||
* (double quotes) or brackets for identifier escaping.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_quoted_identifier = TRUE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Appends the port number to the hostname, if needed.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if ( ! empty($this->port))
|
||||
{
|
||||
$this->hostname .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$this->conn_id = ($persistent)
|
||||
? mssql_pconnect($this->hostname, $this->username, $this->password)
|
||||
: mssql_connect($this->hostname, $this->username, $this->password);
|
||||
|
||||
if ( ! $this->conn_id)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
// Select the DB... assuming a database name is specified in the config file
|
||||
if ($this->database !== '' && ! $this->db_select())
|
||||
{
|
||||
Logger::logError('Unable to select database: '.$this->database);
|
||||
|
||||
return ($this->db_debug === TRUE)
|
||||
? $this->display_error('db_unable_to_select', $this->database)
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
// Determine how identifiers are escaped
|
||||
$query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
|
||||
$query = $query->row_array();
|
||||
$this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
|
||||
$this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']');
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Select the database
|
||||
*
|
||||
* @param string $database
|
||||
* @return bool
|
||||
*/
|
||||
public function db_select($database = '')
|
||||
{
|
||||
if ($database === '')
|
||||
{
|
||||
$database = $this->database;
|
||||
}
|
||||
|
||||
// Note: Escaping is required in the event that the DB name
|
||||
// contains reserved characters.
|
||||
if (mssql_select_db('['.$database.']', $this->conn_id))
|
||||
{
|
||||
$this->database = $database;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return mixed resource if rows are returned, bool otherwise
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return mssql_query($sql, $this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
return $this->simple_query('BEGIN TRAN');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
return $this->simple_query('COMMIT TRAN');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
return $this->simple_query('ROLLBACK TRAN');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return mssql_rows_affected($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* Returns the last id created in the Identity column.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
$query = version_compare($this->version(), '8', '>=')
|
||||
? 'SELECT SCOPE_IDENTITY() AS last_id'
|
||||
: 'SELECT @@IDENTITY AS last_id';
|
||||
|
||||
$query = $this->query($query);
|
||||
$query = $query->row();
|
||||
return $query->last_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set client character set
|
||||
*
|
||||
* @param string $charset
|
||||
* @return bool
|
||||
*/
|
||||
protected function _db_set_charset($charset)
|
||||
{
|
||||
return (ini_set('mssql.charset', $charset) !== FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Version number query string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _version()
|
||||
{
|
||||
return "SELECT SERVERPROPERTY('ProductVersion') AS ver";
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT '.$this->escape_identifiers('name')
|
||||
.' FROM '.$this->escape_identifiers('sysobjects')
|
||||
.' WHERE '.$this->escape_identifiers('type')." = 'U'";
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql.' ORDER BY '.$this->escape_identifiers('name');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT COLUMN_NAME
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->COLUMN_NAME;
|
||||
$retval[$i]->type = $query[$i]->DATA_TYPE;
|
||||
$retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION;
|
||||
$retval[$i]->default = $query[$i]->COLUMN_DEFAULT;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occured.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
// We need this because the error info is discarded by the
|
||||
// server the first time you request it, and query() already
|
||||
// calls error() once for logging purposes when a query fails.
|
||||
static $error = array('code' => 0, 'message' => NULL);
|
||||
|
||||
$message = mssql_get_last_message();
|
||||
if ( ! empty($message))
|
||||
{
|
||||
$error['code'] = $this->query('SELECT @@ERROR AS code')->row()->code;
|
||||
$error['message'] = $message;
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
$this->qb_orderby = array();
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'TRUNCATE TABLE '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
if ($this->qb_limit)
|
||||
{
|
||||
return 'WITH fw_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM fw_delete';
|
||||
}
|
||||
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
$limit = $this->qb_offset + $this->qb_limit;
|
||||
|
||||
// As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported,
|
||||
// however an ORDER BY clause is required for it to work
|
||||
if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby))
|
||||
{
|
||||
$orderby = $this->_compile_order_by();
|
||||
|
||||
// We have to strip the ORDER BY clause
|
||||
$sql = trim(substr($sql, 0, strrpos($sql, $orderby)));
|
||||
|
||||
// Get the fields to select from our subquery, so that we can avoid FW_rownum appearing in the actual results
|
||||
if (count($this->qb_select) === 0)
|
||||
{
|
||||
$select = '*'; // Inevitable
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use only field names and their aliases, everything else is out of our scope.
|
||||
$select = array();
|
||||
$field_regexp = ($this->_quoted_identifier)
|
||||
? '("[^\"]+")' : '(\[[^\]]+\])';
|
||||
for ($i = 0, $c = count($this->qb_select); $i < $c; $i++)
|
||||
{
|
||||
$select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m)
|
||||
? $m[1] : $this->qb_select[$i];
|
||||
}
|
||||
$select = implode(', ', $select);
|
||||
}
|
||||
|
||||
return 'SELECT '.$select." FROM (\n\n"
|
||||
.preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('FW_rownum').', ', $sql)
|
||||
."\n\n) ".$this->escape_identifiers('FW_subquery')
|
||||
."\nWHERE ".$this->escape_identifiers('FW_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit;
|
||||
}
|
||||
|
||||
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert batch statement
|
||||
*
|
||||
* Generates a platform-specific insert string from the supplied data.
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $keys INSERT keys
|
||||
* @param array $values INSERT values
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function _insert_batch($table, $keys, $values)
|
||||
{
|
||||
// Multiple-value inserts are only supported as of SQL Server 2008
|
||||
if (version_compare($this->version(), '10', '>='))
|
||||
{
|
||||
return parent::_insert_batch($table, $keys, $values);
|
||||
}
|
||||
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
mssql_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* MS SQL Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_mssql_forge extends FW_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT' => 'SMALLINT',
|
||||
'SMALLINT' => 'INT',
|
||||
'INT' => 'BIGINT',
|
||||
'REAL' => 'FLOAT'
|
||||
);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
$sqls[] = $sql.$this->_process_column($field[$i]);
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INTEGER':
|
||||
$attributes['TYPE'] = 'INT';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['auto_increment'] = ' IDENTITY(1,1)';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,194 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* MSSQL Result Class
|
||||
*
|
||||
* This class extends the parent result class: FW_DB_result
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_mssql_result extends FW_DB_result {
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
return is_int($this->num_rows)
|
||||
? $this->num_rows
|
||||
: $this->num_rows = mssql_num_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return mssql_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
mssql_field_seek($this->result_id, 0);
|
||||
while ($field = mssql_fetch_field($this->result_id))
|
||||
{
|
||||
$field_names[] = $field->name;
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$field = mssql_fetch_field($this->result_id, $i);
|
||||
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $field->name;
|
||||
$retval[$i]->type = $field->type;
|
||||
$retval[$i]->max_length = $field->max_length;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_resource($this->result_id))
|
||||
{
|
||||
mssql_free_result($this->result_id);
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* @param int $n
|
||||
* @return bool
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
return mssql_data_seek($this->result_id, $n);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return mssql_fetch_assoc($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
$row = mssql_fetch_object($this->result_id);
|
||||
|
||||
if ($class_name === 'stdClass' OR ! $row)
|
||||
{
|
||||
return $row;
|
||||
}
|
||||
|
||||
$class_name = new $class_name();
|
||||
foreach ($row as $key => $value)
|
||||
{
|
||||
$class_name->$key = $value;
|
||||
}
|
||||
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* MS SQL Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_mssql_utility extends FW_DB_utility {
|
||||
|
||||
/**
|
||||
* List databases statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_list_databases = 'EXEC sp_helpdb'; // Can also be: EXEC sp_databases
|
||||
|
||||
/**
|
||||
* OPTIMIZE TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_optimize_table = 'ALTER INDEX all ON %s REORGANIZE';
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return bool
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// Currently unsupported
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,492 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Logger;
|
||||
use FuzeWorks\Exception\DatabaseException;
|
||||
|
||||
/**
|
||||
* MySQL Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_mysql_driver extends FW_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'mysql';
|
||||
|
||||
/**
|
||||
* Compression flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $compress = FALSE;
|
||||
|
||||
/**
|
||||
* DELETE hack flag
|
||||
*
|
||||
* Whether to use the MySQL "delete hack" which allows the number
|
||||
* of affected rows to be shown. Uses a preg_replace when enabled,
|
||||
* adding a bit more processing to all queries.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $delete_hack = TRUE;
|
||||
|
||||
/**
|
||||
* Strict ON flag
|
||||
*
|
||||
* Whether we're running in strict SQL mode.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $stricton;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '`';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if ( ! empty($this->port))
|
||||
{
|
||||
$this->hostname .= ':'.$this->port;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$client_flags = ($this->compress === FALSE) ? 0 : MYSQL_CLIENT_COMPRESS;
|
||||
|
||||
if ($this->encrypt === TRUE)
|
||||
{
|
||||
$client_flags = $client_flags | MYSQL_CLIENT_SSL;
|
||||
}
|
||||
|
||||
// Error suppression is necessary mostly due to PHP 5.5+ issuing E_DEPRECATED messages
|
||||
$this->conn_id = ($persistent === TRUE)
|
||||
? mysql_pconnect($this->hostname, $this->username, $this->password, $client_flags)
|
||||
: mysql_connect($this->hostname, $this->username, $this->password, TRUE, $client_flags);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
// Select the DB... assuming a database name is specified in the config file
|
||||
if ($this->database !== '' && ! $this->db_select())
|
||||
{
|
||||
Logger::logError('Unable to select database: '.$this->database);
|
||||
|
||||
return ($this->db_debug === TRUE)
|
||||
? $this->display_error('db_unable_to_select', $this->database)
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
if (isset($this->stricton) && is_resource($this->conn_id))
|
||||
{
|
||||
if ($this->stricton)
|
||||
{
|
||||
$this->simple_query('SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->simple_query(
|
||||
'SET SESSION sql_mode =
|
||||
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
|
||||
@@sql_mode,
|
||||
"STRICT_ALL_TABLES,", ""),
|
||||
",STRICT_ALL_TABLES", ""),
|
||||
"STRICT_ALL_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES,", ""),
|
||||
",STRICT_TRANS_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES", "")'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reconnect
|
||||
*
|
||||
* Keep / reestablish the db connection if no queries have been
|
||||
* sent for a length of time exceeding the server's idle timeout
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reconnect()
|
||||
{
|
||||
if (mysql_ping($this->conn_id) === FALSE)
|
||||
{
|
||||
$this->conn_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Select the database
|
||||
*
|
||||
* @param string $database
|
||||
* @return bool
|
||||
*/
|
||||
public function db_select($database = '')
|
||||
{
|
||||
if ($database === '')
|
||||
{
|
||||
$database = $this->database;
|
||||
}
|
||||
|
||||
if (mysql_select_db($database, $this->conn_id))
|
||||
{
|
||||
$this->database = $database;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set client character set
|
||||
*
|
||||
* @param string $charset
|
||||
* @return bool
|
||||
*/
|
||||
protected function _db_set_charset($charset)
|
||||
{
|
||||
return mysql_set_charset($charset, $this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
if ( ! $this->conn_id OR ($version = mysql_get_server_info($this->conn_id)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return $this->data_cache['version'] = $version;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return mysql_query($this->_prep_query($sql), $this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Prep the query
|
||||
*
|
||||
* If needed, each database adapter can prep the query string
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return string
|
||||
*/
|
||||
protected function _prep_query($sql)
|
||||
{
|
||||
// mysql_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack
|
||||
// modifies the query so that it a proper number of affected rows is returned.
|
||||
if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
|
||||
{
|
||||
return trim($sql).' WHERE 1=1';
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
$this->simple_query('SET AUTOCOMMIT=0');
|
||||
return $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
if ($this->simple_query('COMMIT'))
|
||||
{
|
||||
$this->simple_query('SET AUTOCOMMIT=1');
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
if ($this->simple_query('ROLLBACK'))
|
||||
{
|
||||
$this->simple_query('SET AUTOCOMMIT=1');
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependant string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
return mysql_real_escape_string($str, $this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return mysql_affected_rows($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
return mysql_insert_id($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SHOW TABLES FROM '.$this->escape_identifiers($this->database);
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->Field;
|
||||
|
||||
sscanf($query[$i]->Type, '%[a-z](%d)',
|
||||
$retval[$i]->type,
|
||||
$retval[$i]->max_length
|
||||
);
|
||||
|
||||
$retval[$i]->default = $query[$i]->Default;
|
||||
$retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occured.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return array('code' => mysql_errno($this->conn_id), 'message' => mysql_error($this->conn_id));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FROM tables
|
||||
*
|
||||
* Groups tables in FROM clauses if needed, so there is no confusion
|
||||
* about operator precedence.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _from_tables()
|
||||
{
|
||||
if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
|
||||
{
|
||||
return '('.implode(', ', $this->qb_from).')';
|
||||
}
|
||||
|
||||
return implode(', ', $this->qb_from);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
// Error suppression to avoid annoying E_WARNINGs in cases
|
||||
// where the connection has already been closed for some reason.
|
||||
@mysql_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,240 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* MySQL Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_mysql_forge extends FW_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
|
||||
|
||||
/**
|
||||
* CREATE TABLE keys flag
|
||||
*
|
||||
* Whether table keys are created from within the
|
||||
* CREATE TABLE statement.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_create_table_keys = TRUE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT',
|
||||
'SMALLINT',
|
||||
'MEDIUMINT',
|
||||
'INT',
|
||||
'INTEGER',
|
||||
'BIGINT',
|
||||
'REAL',
|
||||
'DOUBLE',
|
||||
'DOUBLE PRECISION',
|
||||
'FLOAT',
|
||||
'DECIMAL',
|
||||
'NUMERIC'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CREATE TABLE attributes
|
||||
*
|
||||
* @param array $attributes Associative array of table attributes
|
||||
* @return string
|
||||
*/
|
||||
protected function _create_table_attr($attributes)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
foreach (array_keys($attributes) as $key)
|
||||
{
|
||||
if (is_string($key))
|
||||
{
|
||||
$sql .= ' '.strtoupper($key).' = '.$attributes[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty($this->db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET'))
|
||||
{
|
||||
$sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set;
|
||||
}
|
||||
|
||||
if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE'))
|
||||
{
|
||||
$sql .= ' COLLATE = '.$this->db->dbcollat;
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP')
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$field[$i] = ($alter_type === 'ADD')
|
||||
? "\n\tADD ".$field[$i]['_literal']
|
||||
: "\n\tMODIFY ".$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($alter_type === 'ADD')
|
||||
{
|
||||
$field[$i]['_literal'] = "\n\tADD ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
|
||||
}
|
||||
|
||||
$field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return array($sql.implode(',', $field));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
$extra_clause = isset($field['after'])
|
||||
? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
|
||||
|
||||
if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
|
||||
{
|
||||
$extra_clause = ' FIRST';
|
||||
}
|
||||
|
||||
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name']))
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['unsigned']
|
||||
.$field['null']
|
||||
.$field['default']
|
||||
.$field['auto_increment']
|
||||
.$field['unique']
|
||||
.(empty($field['comment']) ? '' : ' COMMENT '.$field['comment'])
|
||||
.$extra_clause;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process indexes
|
||||
*
|
||||
* @param string $table (ignored)
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_indexes($table)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
for ($i = 0, $c = count($this->keys); $i < $c; $i++)
|
||||
{
|
||||
if (is_array($this->keys[$i]))
|
||||
{
|
||||
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
|
||||
{
|
||||
if ( ! isset($this->fields[$this->keys[$i][$i2]]))
|
||||
{
|
||||
unset($this->keys[$i][$i2]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( ! isset($this->fields[$this->keys[$i]]))
|
||||
{
|
||||
unset($this->keys[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
|
||||
|
||||
$sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
|
||||
.' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
|
||||
}
|
||||
|
||||
$this->keys = array();
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,196 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* MySQL Result Class
|
||||
*
|
||||
* This class extends the parent result class: FW_DB_result
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_mysql_result extends FW_DB_result {
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object &$driver_object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$driver_object)
|
||||
{
|
||||
parent::__construct($driver_object);
|
||||
|
||||
// Required, due to mysql_data_seek() causing nightmares
|
||||
// with empty result sets
|
||||
$this->num_rows = mysql_num_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
return $this->num_rows;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return mysql_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
mysql_field_seek($this->result_id, 0);
|
||||
while ($field = mysql_fetch_field($this->result_id))
|
||||
{
|
||||
$field_names[] = $field->name;
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = mysql_field_name($this->result_id, $i);
|
||||
$retval[$i]->type = mysql_field_type($this->result_id, $i);
|
||||
$retval[$i]->max_length = mysql_field_len($this->result_id, $i);
|
||||
$retval[$i]->primary_key = (int) (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') !== FALSE);
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_resource($this->result_id))
|
||||
{
|
||||
mysql_free_result($this->result_id);
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* @param int $n
|
||||
* @return bool
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
return $this->num_rows
|
||||
? mysql_data_seek($this->result_id, $n)
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return mysql_fetch_assoc($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return mysql_fetch_object($this->result_id, $class_name);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,208 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* MySQL Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_mysql_utility extends FW_DB_utility {
|
||||
|
||||
/**
|
||||
* List databases statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_list_databases = 'SHOW DATABASES';
|
||||
|
||||
/**
|
||||
* OPTIMIZE TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_optimize_table = 'OPTIMIZE TABLE %s';
|
||||
|
||||
/**
|
||||
* REPAIR TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_repair_table = 'REPAIR TABLE %s';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
if (count($params) === 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Extract the prefs for simplicity
|
||||
extract($params);
|
||||
|
||||
// Build the output
|
||||
$output = '';
|
||||
|
||||
// Do we need to include a statement to disable foreign key checks?
|
||||
if ($foreign_key_checks === FALSE)
|
||||
{
|
||||
$output .= 'SET foreign_key_checks = 0;'.$newline;
|
||||
}
|
||||
|
||||
foreach ( (array) $tables as $table)
|
||||
{
|
||||
// Is the table in the "ignore" list?
|
||||
if (in_array($table, (array) $ignore, TRUE))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the table schema
|
||||
$query = $this->db->query('SHOW CREATE TABLE '.$this->db->escape_identifiers($this->db->database.'.'.$table));
|
||||
|
||||
// No result means the table name was invalid
|
||||
if ($query === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Write out the table schema
|
||||
$output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline;
|
||||
|
||||
if ($add_drop === TRUE)
|
||||
{
|
||||
$output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$result = $query->result_array();
|
||||
foreach ($result[0] as $val)
|
||||
{
|
||||
if ($i++ % 2)
|
||||
{
|
||||
$output .= $val.';'.$newline.$newline;
|
||||
}
|
||||
}
|
||||
|
||||
// If inserts are not needed we're done...
|
||||
if ($add_insert === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Grab all the data from the current table
|
||||
$query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table));
|
||||
|
||||
if ($query->num_rows() === 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fetch the field names and determine if the field is an
|
||||
// integer type. We use this info to decide whether to
|
||||
// surround the data with quotes or not
|
||||
|
||||
$i = 0;
|
||||
$field_str = '';
|
||||
$is_int = array();
|
||||
while ($field = mysql_fetch_field($query->result_id))
|
||||
{
|
||||
// Most versions of MySQL store timestamp as a string
|
||||
$is_int[$i] = in_array(strtolower(mysql_field_type($query->result_id, $i)),
|
||||
array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
|
||||
TRUE);
|
||||
|
||||
// Create a string of field names
|
||||
$field_str .= $this->db->escape_identifiers($field->name).', ';
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Trim off the end comma
|
||||
$field_str = preg_replace('/, $/' , '', $field_str);
|
||||
|
||||
// Build the insert string
|
||||
foreach ($query->result_array() as $row)
|
||||
{
|
||||
$val_str = '';
|
||||
|
||||
$i = 0;
|
||||
foreach ($row as $v)
|
||||
{
|
||||
// Is the value NULL?
|
||||
if ($v === NULL)
|
||||
{
|
||||
$val_str .= 'NULL';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Escape the data if it's not an integer
|
||||
$val_str .= ($is_int[$i] === FALSE) ? $this->db->escape($v) : $v;
|
||||
}
|
||||
|
||||
// Append a comma
|
||||
$val_str .= ', ';
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Remove the comma at the end of the string
|
||||
$val_str = preg_replace('/, $/' , '', $val_str);
|
||||
|
||||
// Build the INSERT string
|
||||
$output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
|
||||
}
|
||||
|
||||
$output .= $newline.$newline;
|
||||
}
|
||||
|
||||
// Do we need to include a statement to re-enable foreign key checks?
|
||||
if ($foreign_key_checks === FALSE)
|
||||
{
|
||||
$output .= 'SET foreign_key_checks = 1;'.$newline;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,6 @@ return array(
|
|||
'subdriver'=> '',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'cachedir' => 'Application/Cache',
|
||||
'char_set' => 'utf8',
|
||||
|
|
Loading…
Reference in New Issue