From 96cebbf83e43545ec77ae999a6b13160f4b9e570 Mon Sep 17 00:00:00 2001 From: Visman Date: Tue, 22 May 2018 10:44:21 +0700 Subject: [PATCH] Delete support MySQL (Original) This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. --- include/dblayer/common_db.php | 8 +- include/dblayer/mysql.php | 373 ----------------------------- include/dblayer/mysql_innodb.php | 387 ------------------------------- install.php | 17 +- 4 files changed, 2 insertions(+), 783 deletions(-) delete mode 100644 include/dblayer/mysql.php delete mode 100644 include/dblayer/mysql_innodb.php diff --git a/include/dblayer/common_db.php b/include/dblayer/common_db.php index e0fabca..8c6c108 100644 --- a/include/dblayer/common_db.php +++ b/include/dblayer/common_db.php @@ -15,17 +15,11 @@ switch ($db_type) { case 'mysql': - require_once PUN_ROOT.'include/dblayer/mysql.php'; - break; - - case 'mysql_innodb': - require_once PUN_ROOT.'include/dblayer/mysql_innodb.php'; - break; - case 'mysqli': require_once PUN_ROOT.'include/dblayer/mysqli.php'; break; + case 'mysql_innodb': case 'mysqli_innodb': require_once PUN_ROOT.'include/dblayer/mysqli_innodb.php'; break; diff --git a/include/dblayer/mysql.php b/include/dblayer/mysql.php deleted file mode 100644 index 7f48417..0000000 --- a/include/dblayer/mysql.php +++ /dev/null @@ -1,373 +0,0 @@ - 'INT(10) UNSIGNED AUTO_INCREMENT' - ); - - - function __construct($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect) - { - $this->prefix = $db_prefix; - - if ($p_connect) - $this->link_id = @mysql_pconnect($db_host, $db_username, $db_password); - else - $this->link_id = @mysql_connect($db_host, $db_username, $db_password); - - if ($this->link_id) - { - if (!@mysql_select_db($db_name, $this->link_id)) - error('Unable to select database. MySQL reported: '.mysql_error(), __FILE__, __LINE__); - } - else - error('Unable to connect to MySQL server. MySQL reported: '.mysql_error(), __FILE__, __LINE__); - - // Setup the client-server character set (UTF-8) - if (!defined('FORUM_NO_SET_NAMES')) - { - if (!$this->set_names('utf8')) - error('Unable to set the character set.', __FILE__, __LINE__); - } - } - - - function start_transaction() - { - return; - } - - - function end_transaction() - { - return; - } - - - function query($sql, $unbuffered = false) - { - if (defined('PUN_SHOW_QUERIES')) - $q_start = microtime(true); - - if ($unbuffered) - $this->query_result = @mysql_unbuffered_query($sql, $this->link_id); - else - $this->query_result = @mysql_query($sql, $this->link_id); - - if ($this->query_result) - { - if (defined('PUN_SHOW_QUERIES')) - $this->saved_queries[] = array($sql, sprintf('%.5f', microtime(true) - $q_start)); - - ++$this->num_queries; - - return $this->query_result; - } - else - { - if (defined('PUN_SHOW_QUERIES')) - $this->saved_queries[] = array($sql, 0); - - $this->error_no = @mysql_errno($this->link_id); - $this->error_msg = @mysql_error($this->link_id); - - return false; - } - } - - - function result($query_id = 0, $row = 0, $col = 0) - { - return ($query_id) ? @mysql_result($query_id, $row, $col) : false; - } - - - function fetch_assoc($query_id = 0) - { - return ($query_id) ? @mysql_fetch_assoc($query_id) : false; - } - - - function fetch_row($query_id = 0) - { - return ($query_id) ? @mysql_fetch_row($query_id) : false; - } - - - function num_rows($query_id = 0) - { - return ($query_id) ? @mysql_num_rows($query_id) : false; - } - - - function affected_rows() - { - return ($this->link_id) ? @mysql_affected_rows($this->link_id) : false; - } - - - function insert_id() - { - return ($this->link_id) ? @mysql_insert_id($this->link_id) : false; - } - - - function get_num_queries() - { - return $this->num_queries; - } - - - function get_saved_queries() - { - return $this->saved_queries; - } - - - function free_result($query_id = false) - { - return ($query_id) ? @mysql_free_result($query_id) : false; - } - - - function escape($str) - { - if (is_array($str)) - return ''; - else if (function_exists('mysql_real_escape_string')) - return mysql_real_escape_string($str, $this->link_id); - else - return mysql_escape_string($str); - } - - - function error() - { - $result['error_sql'] = @current(@end($this->saved_queries)); - $result['error_no'] = $this->error_no; - $result['error_msg'] = $this->error_msg; - - return $result; - } - - - function close() - { - if ($this->link_id) - { - if (is_resource($this->query_result)) - @mysql_free_result($this->query_result); - - return @mysql_close($this->link_id); - } - else - return false; - } - - function get_names() - { - $result = $this->query('SHOW VARIABLES LIKE \'character_set_connection\''); - return $this->result($result, 0, 1); - } - - - function set_names($names) - { - return @mysql_set_charset($names, $this->link_id); - } - - - function get_version() - { - $result = $this->query('SELECT VERSION()'); - - return array( - 'name' => 'MySQL Standard', - 'version' => preg_replace('%^([^-]+).*$%', '\\1', $this->result($result)) - ); - } - - - function table_exists($table_name, $no_prefix = false) - { - $result = $this->query('SHOW TABLES LIKE \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\''); - return $this->num_rows($result) > 0; - } - - - function field_exists($table_name, $field_name, $no_prefix = false) - { - $result = $this->query('SHOW COLUMNS FROM '.($no_prefix ? '' : $this->prefix).$table_name.' LIKE \''.$this->escape($field_name).'\''); - return $this->num_rows($result) > 0; - } - - - function index_exists($table_name, $index_name, $no_prefix = false) - { - $exists = false; - - $result = $this->query('SHOW INDEX FROM '.($no_prefix ? '' : $this->prefix).$table_name); - while ($cur_index = $this->fetch_assoc($result)) - { - if (strtolower($cur_index['Key_name']) == strtolower(($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name)) - { - $exists = true; - break; - } - } - - return $exists; - } - - - function create_table($table_name, $schema, $no_prefix = false) - { - if ($this->table_exists($table_name, $no_prefix)) - return true; - - $query = 'CREATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name." (\n"; - - // Go through every schema element and add it to the query - foreach ($schema['FIELDS'] as $field_name => $field_data) - { - $field_data['datatype'] = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_data['datatype']); - - $query .= $field_name.' '.$field_data['datatype']; - - if (isset($field_data['collation'])) - $query .= 'CHARACTER SET utf8 COLLATE utf8_'.$field_data['collation']; - - if (!$field_data['allow_null']) - $query .= ' NOT NULL'; - - if (isset($field_data['default'])) - $query .= ' DEFAULT '.$field_data['default']; - - $query .= ",\n"; - } - - // If we have a primary key, add it - if (isset($schema['PRIMARY KEY'])) - $query .= 'PRIMARY KEY ('.implode(',', $schema['PRIMARY KEY']).'),'."\n"; - - // Add unique keys - if (isset($schema['UNIQUE KEYS'])) - { - foreach ($schema['UNIQUE KEYS'] as $key_name => $key_fields) - $query .= 'UNIQUE KEY '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$key_name.'('.implode(',', $key_fields).'),'."\n"; - } - - // Add indexes - if (isset($schema['INDEXES'])) - { - foreach ($schema['INDEXES'] as $index_name => $index_fields) - $query .= 'KEY '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.'('.implode(',', $index_fields).'),'."\n"; - } - - // We remove the last two characters (a newline and a comma) and add on the ending - $query = substr($query, 0, strlen($query) - 2)."\n".') ENGINE = '.(isset($schema['ENGINE']) ? $schema['ENGINE'] : 'MyISAM').' CHARACTER SET utf8'; - - return $this->query($query) ? true : false; - } - - - function drop_table($table_name, $no_prefix = false) - { - if (!$this->table_exists($table_name, $no_prefix)) - return true; - - return $this->query('DROP TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false; - } - - - function rename_table($old_table, $new_table, $no_prefix = false) - { - // If the new table exists and the old one doesn't, then we're happy - if ($this->table_exists($new_table, $no_prefix) && !$this->table_exists($old_table, $no_prefix)) - return true; - - return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$old_table.' RENAME TO '.($no_prefix ? '' : $this->prefix).$new_table) ? true : false; - } - - - function add_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false) - { - if ($this->field_exists($table_name, $field_name, $no_prefix)) - return true; - - $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type); - - if (!is_null($default_value) && !is_int($default_value) && !is_float($default_value)) - $default_value = '\''.$this->escape($default_value).'\''; - - return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.$field_name.' '.$field_type.($allow_null ? '' : ' NOT NULL').(!is_null($default_value) ? ' DEFAULT '.$default_value : '').(!is_null($after_field) ? ' AFTER '.$after_field : '')) ? true : false; - } - - - function alter_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false) - { - if (!$this->field_exists($table_name, $field_name, $no_prefix)) - return true; - - $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type); - - if (!is_null($default_value) && !is_int($default_value) && !is_float($default_value)) - $default_value = '\''.$this->escape($default_value).'\''; - - return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' MODIFY '.$field_name.' '.$field_type.($allow_null ? '' : ' NOT NULL').(!is_null($default_value) ? ' DEFAULT '.$default_value : '').(!is_null($after_field) ? ' AFTER '.$after_field : '')) ? true : false; - } - - - function drop_field($table_name, $field_name, $no_prefix = false) - { - if (!$this->field_exists($table_name, $field_name, $no_prefix)) - return true; - - return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP '.$field_name) ? true : false; - } - - - function add_index($table_name, $index_name, $index_fields, $unique = false, $no_prefix = false) - { - if ($this->index_exists($table_name, $index_name, $no_prefix)) - return true; - - return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.($unique ? 'UNIQUE ' : '').'INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.' ('.implode(',', $index_fields).')') ? true : false; - } - - - function drop_index($table_name, $index_name, $no_prefix = false) - { - if (!$this->index_exists($table_name, $index_name, $no_prefix)) - return true; - - return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name) ? true : false; - } - - function truncate_table($table_name, $no_prefix = false) - { - return $this->query('TRUNCATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false; - } -} diff --git a/include/dblayer/mysql_innodb.php b/include/dblayer/mysql_innodb.php deleted file mode 100644 index 3662bf6..0000000 --- a/include/dblayer/mysql_innodb.php +++ /dev/null @@ -1,387 +0,0 @@ - 'INT(10) UNSIGNED AUTO_INCREMENT' - ); - - - function __construct($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect) - { - $this->prefix = $db_prefix; - - if ($p_connect) - $this->link_id = @mysql_pconnect($db_host, $db_username, $db_password); - else - $this->link_id = @mysql_connect($db_host, $db_username, $db_password); - - if ($this->link_id) - { - if (!@mysql_select_db($db_name, $this->link_id)) - error('Unable to select database. MySQL reported: '.mysql_error(), __FILE__, __LINE__); - } - else - error('Unable to connect to MySQL server. MySQL reported: '.mysql_error(), __FILE__, __LINE__); - - // Setup the client-server character set (UTF-8) - if (!defined('FORUM_NO_SET_NAMES')) - { - if (!$this->set_names('utf8')) - error('Unable to set the character set.', __FILE__, __LINE__); - } - } - - - function start_transaction() - { - ++$this->in_transaction; - - mysql_query('START TRANSACTION', $this->link_id); - return; - } - - - function end_transaction() - { - --$this->in_transaction; - - mysql_query('COMMIT', $this->link_id); - return; - } - - - function query($sql, $unbuffered = false) - { - if (defined('PUN_SHOW_QUERIES')) - $q_start = microtime(true); - - if ($unbuffered) - $this->query_result = @mysql_unbuffered_query($sql, $this->link_id); - else - $this->query_result = @mysql_query($sql, $this->link_id); - - if ($this->query_result) - { - if (defined('PUN_SHOW_QUERIES')) - $this->saved_queries[] = array($sql, sprintf('%.5f', microtime(true) - $q_start)); - - ++$this->num_queries; - - return $this->query_result; - } - else - { - if (defined('PUN_SHOW_QUERIES')) - $this->saved_queries[] = array($sql, 0); - - $this->error_no = @mysql_errno($this->link_id); - $this->error_msg = @mysql_error($this->link_id); - - // Rollback transaction - if ($this->in_transaction) - mysql_query('ROLLBACK', $this->link_id); - - --$this->in_transaction; - - return false; - } - } - - - function result($query_id = 0, $row = 0, $col = 0) - { - return ($query_id) ? @mysql_result($query_id, $row, $col) : false; - } - - - function fetch_assoc($query_id = 0) - { - return ($query_id) ? @mysql_fetch_assoc($query_id) : false; - } - - - function fetch_row($query_id = 0) - { - return ($query_id) ? @mysql_fetch_row($query_id) : false; - } - - - function num_rows($query_id = 0) - { - return ($query_id) ? @mysql_num_rows($query_id) : false; - } - - - function affected_rows() - { - return ($this->link_id) ? @mysql_affected_rows($this->link_id) : false; - } - - - function insert_id() - { - return ($this->link_id) ? @mysql_insert_id($this->link_id) : false; - } - - - function get_num_queries() - { - return $this->num_queries; - } - - - function get_saved_queries() - { - return $this->saved_queries; - } - - - function free_result($query_id = false) - { - return ($query_id) ? @mysql_free_result($query_id) : false; - } - - - function escape($str) - { - if (is_array($str)) - return ''; - else if (function_exists('mysql_real_escape_string')) - return mysql_real_escape_string($str, $this->link_id); - else - return mysql_escape_string($str); - } - - - function error() - { - $result['error_sql'] = @current(@end($this->saved_queries)); - $result['error_no'] = $this->error_no; - $result['error_msg'] = $this->error_msg; - - return $result; - } - - - function close() - { - if ($this->link_id) - { - if (is_resource($this->query_result)) - @mysql_free_result($this->query_result); - - return @mysql_close($this->link_id); - } - else - return false; - } - - - function get_names() - { - $result = $this->query('SHOW VARIABLES LIKE \'character_set_connection\''); - return $this->result($result, 0, 1); - } - - - function set_names($names) - { - return @mysql_set_charset($names, $this->link_id); - } - - - function get_version() - { - $result = $this->query('SELECT VERSION()'); - - return array( - 'name' => 'MySQL Standard (InnoDB)', - 'version' => preg_replace('%^([^-]+).*$%', '\\1', $this->result($result)) - ); - } - - - function table_exists($table_name, $no_prefix = false) - { - $result = $this->query('SHOW TABLES LIKE \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\''); - return $this->num_rows($result) > 0; - } - - - function field_exists($table_name, $field_name, $no_prefix = false) - { - $result = $this->query('SHOW COLUMNS FROM '.($no_prefix ? '' : $this->prefix).$table_name.' LIKE \''.$this->escape($field_name).'\''); - return $this->num_rows($result) > 0; - } - - - function index_exists($table_name, $index_name, $no_prefix = false) - { - $exists = false; - - $result = $this->query('SHOW INDEX FROM '.($no_prefix ? '' : $this->prefix).$table_name); - while ($cur_index = $this->fetch_assoc($result)) - { - if (strtolower($cur_index['Key_name']) == strtolower(($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name)) - { - $exists = true; - break; - } - } - - return $exists; - } - - - function create_table($table_name, $schema, $no_prefix = false) - { - if ($this->table_exists($table_name, $no_prefix)) - return true; - - $query = 'CREATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name." (\n"; - - // Go through every schema element and add it to the query - foreach ($schema['FIELDS'] as $field_name => $field_data) - { - $field_data['datatype'] = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_data['datatype']); - - $query .= $field_name.' '.$field_data['datatype']; - - if (isset($field_data['collation'])) - $query .= 'CHARACTER SET utf8 COLLATE utf8_'.$field_data['collation']; - - if (!$field_data['allow_null']) - $query .= ' NOT NULL'; - - if (isset($field_data['default'])) - $query .= ' DEFAULT '.$field_data['default']; - - $query .= ",\n"; - } - - // If we have a primary key, add it - if (isset($schema['PRIMARY KEY'])) - $query .= 'PRIMARY KEY ('.implode(',', $schema['PRIMARY KEY']).'),'."\n"; - - // Add unique keys - if (isset($schema['UNIQUE KEYS'])) - { - foreach ($schema['UNIQUE KEYS'] as $key_name => $key_fields) - $query .= 'UNIQUE KEY '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$key_name.'('.implode(',', $key_fields).'),'."\n"; - } - - // Add indexes - if (isset($schema['INDEXES'])) - { - foreach ($schema['INDEXES'] as $index_name => $index_fields) - $query .= 'KEY '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.'('.implode(',', $index_fields).'),'."\n"; - } - - // We remove the last two characters (a newline and a comma) and add on the ending - $query = substr($query, 0, strlen($query) - 2)."\n".') ENGINE = '.(isset($schema['ENGINE']) ? $schema['ENGINE'] : 'InnoDB').' CHARACTER SET utf8'; - - return $this->query($query) ? true : false; - } - - - function drop_table($table_name, $no_prefix = false) - { - if (!$this->table_exists($table_name, $no_prefix)) - return true; - - return $this->query('DROP TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false; - } - - - function rename_table($old_table, $new_table, $no_prefix = false) - { - // If the new table exists and the old one doesn't, then we're happy - if ($this->table_exists($new_table, $no_prefix) && !$this->table_exists($old_table, $no_prefix)) - return true; - - return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$old_table.' RENAME TO '.($no_prefix ? '' : $this->prefix).$new_table) ? true : false; - } - - - function add_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false) - { - if ($this->field_exists($table_name, $field_name, $no_prefix)) - return true; - - $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type); - - if (!is_null($default_value) && !is_int($default_value) && !is_float($default_value)) - $default_value = '\''.$this->escape($default_value).'\''; - - return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.$field_name.' '.$field_type.($allow_null ? '' : ' NOT NULL').(!is_null($default_value) ? ' DEFAULT '.$default_value : '').(!is_null($after_field) ? ' AFTER '.$after_field : '')) ? true : false; - } - - - function alter_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false) - { - if (!$this->field_exists($table_name, $field_name, $no_prefix)) - return true; - - $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type); - - if (!is_null($default_value) && !is_int($default_value) && !is_float($default_value)) - $default_value = '\''.$this->escape($default_value).'\''; - - return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' MODIFY '.$field_name.' '.$field_type.($allow_null ? '' : ' NOT NULL').(!is_null($default_value) ? ' DEFAULT '.$default_value : '').(!is_null($after_field) ? ' AFTER '.$after_field : '')) ? true : false; - } - - - function drop_field($table_name, $field_name, $no_prefix = false) - { - if (!$this->field_exists($table_name, $field_name, $no_prefix)) - return true; - - return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP '.$field_name) ? true : false; - } - - - function add_index($table_name, $index_name, $index_fields, $unique = false, $no_prefix = false) - { - if ($this->index_exists($table_name, $index_name, $no_prefix)) - return true; - - return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.($unique ? 'UNIQUE ' : '').'INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.' ('.implode(',', $index_fields).')') ? true : false; - } - - - function drop_index($table_name, $index_name, $no_prefix = false) - { - if (!$this->index_exists($table_name, $index_name, $no_prefix)) - return true; - - return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name) ? true : false; - } - - function truncate_table($table_name, $no_prefix = false) - { - return $this->query('TRUNCATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false; - } -} diff --git a/install.php b/install.php index 740b4c3..79d7965 100644 --- a/install.php +++ b/install.php @@ -218,15 +218,6 @@ function generate_config_file() $db_extensions[] = array('mysqli_innodb', 'MySQL Improved (InnoDB)'); $mysql_innodb = true; } - if (function_exists('mysql_connect')) - { - $db_extensions[] = array('mysql', 'MySQL Standard'); - $db_extensions[] = array('mysql_innodb', 'MySQL Standard (InnoDB)'); - $mysql_innodb = true; - - if (count($db_extensions) > 2) - $dual_mysql = true; - } if (function_exists('sqlite_open')) $db_extensions[] = array('sqlite', 'SQLite'); if (class_exists('SQLite3')) @@ -500,17 +491,11 @@ function process_form(the_form) switch ($db_type) { case 'mysql': - require PUN_ROOT.'include/dblayer/mysql.php'; - break; - - case 'mysql_innodb': - require PUN_ROOT.'include/dblayer/mysql_innodb.php'; - break; - case 'mysqli': require PUN_ROOT.'include/dblayer/mysqli.php'; break; + case 'mysql_innodb': case 'mysqli_innodb': require PUN_ROOT.'include/dblayer/mysqli_innodb.php'; break;