diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index 7101f960de..45f0a22db6 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -14,7 +14,7 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -function mysql_connect_db($host = null, $db = null, $user = null, $pass = null, $port = null) { +function mysql_connect_db($host = null, $db = null, $user = null, $pass = null, $port = null, $charset = "utf8") { global $config; if ($host === null) @@ -42,6 +42,8 @@ function mysql_connect_db($host = null, $db = null, $user = null, $pass = null, } db_change_cache_id ($db, $host); + mysqli_set_charset($connect_id, $charset); + mysqli_select_db($connect_id, $db); } else { @@ -52,6 +54,8 @@ function mysql_connect_db($host = null, $db = null, $user = null, $pass = null, db_change_cache_id ($db, $host); + @mysql_set_charset($connect_id, $charset); + mysql_select_db($db, $connect_id); } @@ -1198,47 +1202,6 @@ function mysql_db_get_type_field_table($table, $field) { } } -/** - * Get the element count of a table. - * - * @param string $sql SQL query to get the element count. - * - * @return int Return the number of elements in the table. - */ -function mysql_db_get_table_count($sql, $search_history_db = false) { - global $config; - - $history_count = 0; - $count = mysql_db_get_value_sql ($sql); - if ($count === false) { - $count = 0; - } - - // Search the history DB for matches - if ($search_history_db && $config['history_db_enabled'] == 1) { - - // Connect to the history DB - if (! isset ($config['history_db_connection']) || $config['history_db_connection'] === false) { - if ($config["mysqli"]) { - $config['history_db_connection'] = mysqli_connect_db ($config['history_db_host'], $config['history_db_user'], io_output_password($config['history_db_pass']), $config['history_db_name'], $config['history_db_port'], false); - } - else { - $config['history_db_connection'] = mysql_connect_db ($config['history_db_host'], $config['history_db_name'], $config['history_db_user'], io_output_password($config['history_db_pass']), $config['history_db_port'], false); - } - } - if ($config['history_db_connection'] !== false) { - $history_count = mysql_db_get_value_sql ($sql, $config['history_db_connection']); - if ($history_count === false) { - $history_count = 0; - } - } - } - - $count += $history_count; - - return $count; -} - function mysql_get_fields($table) { global $config; diff --git a/pandora_console/include/db/oracle.php b/pandora_console/include/db/oracle.php index a651eeffa7..4e7cec79f4 100644 --- a/pandora_console/include/db/oracle.php +++ b/pandora_console/include/db/oracle.php @@ -1476,42 +1476,6 @@ function oracle_list_all_field_table($table_name, $return_mode = 'array') { } } -/** - * Get the element count of a table. - * - * @param string $sql SQL query to get the element count. - * - * @return int Return the number of elements in the table. - */ -function oracle_db_get_table_count($sql, $search_history_db = false) { - global $config; - - $history_count = 0; - $count = oracle_db_get_value_sql ($sql); - if ($count === false) { - $count = 0; - } - - // Search the history DB for matches - if ($search_history_db && $config['history_db_enabled'] == 1) { - - // Connect to the history DB - if (! isset ($config['history_db_connection']) || $config['history_db_connection'] === false) { - $config['history_db_connection'] = oracle_connect_db ($config['history_db_host'], $config['history_db_name'], $config['history_db_user'], io_output_password($config['history_db_pass']), $config['history_db_port'], false); - } - if ($config['history_db_connection'] !== false) { - $history_count = oracle_db_get_value_sql ($sql, $config['history_db_connection']); - if ($history_count === false) { - $history_count = 0; - } - } - } - - $count += $history_count; - - return $count; -} - /** * Process a file with an oracle schema sentences. * Based on the function which installs the pandoradb.sql schema. diff --git a/pandora_console/include/db/postgresql.php b/pandora_console/include/db/postgresql.php index 7b1bd56ec0..1b74f21b07 100644 --- a/pandora_console/include/db/postgresql.php +++ b/pandora_console/include/db/postgresql.php @@ -1055,40 +1055,5 @@ function postgresql_db_get_type_field_table($table, $field) { return pg_field_type($result, $field); } -/** - * Get the element count of a table. - * - * @param string $sql SQL query to get the element count. - * - * @return int Return the number of elements in the table. - */ -function postgresql_db_get_table_count($sql, $search_history_db = false) { - global $config; - - $history_count = 0; - $count = postgresql_db_get_value_sql ($sql); - if ($count === false) { - $count = 0; - } - - // Search the history DB for matches - if ($search_history_db && $config['history_db_enabled'] == 1) { - - // Connect to the history DB - if (! isset ($config['history_db_connection']) || $config['history_db_connection'] === false) { - $config['history_db_connection'] = postgresql_connect_db ($config['history_db_host'], $config['history_db_name'], $config['history_db_user'], io_output_password($config['history_db_pass']), $config['history_db_port'], false); - } - if ($config['history_db_connection'] !== false) { - $history_count = postgresql_db_get_value_sql ($sql, $config['history_db_connection']); - if ($history_count === false) { - $history_count = 0; - } - } - } - - $count += $history_count; - - return $count; -} ?> diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index aaf61db8cd..063897ea74 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -43,13 +43,13 @@ function db_select_engine() { } } -function db_connect($host = null, $db = null, $user = null, $pass = null, $port = null, $critical = true) { +function db_connect($host = null, $db = null, $user = null, $pass = null, $port = null, $critical = true, $charset = "utf8") { global $config; static $error = 0; switch ($config["dbtype"]) { case "mysql": - $return = mysql_connect_db($host, $db, $user, $pass, $port); + $return = mysql_connect_db($host, $db, $user, $pass, $port, $charset); break; case "postgresql": $return = postgresql_connect_db($host, $db, $user, $pass, $port); @@ -1654,28 +1654,12 @@ function db_get_type_field_table($table, $field) { } /** - * Get the element count of a table. + * Get the columns of a table. * - * @param string $sql SQL query to get the element count. + * @param string $table table to retrieve columns. * - * @return int Return the number of elements in the table. + * @return array with column names. */ -function db_get_table_count($table, $search_history_db = false) { - global $config; - - switch ($config["dbtype"]) { - case "mysql": - return mysql_db_get_table_count($table, $search_history_db); - break; - case "postgresql": - return postgresql_db_get_table_count($table, $search_history_db); - break; - case "oracle": - return oracle_db_get_table_count($table, $search_history_db); - break; - } -} - function db_get_fields($table) { global $config;