/**
 * Main function for the routines functionality
 *
 * @param string $type 'FUNCTION' for functions,
 *                     'PROCEDURE' for procedures,
 *                     null for both
 *
 * @return void
 */
function PMA_RTN_main($type)
{
    global $db;
    PMA_RTN_setGlobals();
    /**
     * Process all requests
     */
    PMA_RTN_handleEditor();
    PMA_RTN_handleExecute();
    PMA_RTN_handleExport();
    /**
     * Display a list of available routines
     */
    if (!PMA_isValid($type, array('FUNCTION', 'PROCEDURE'))) {
        $type = null;
    }
    $items = $GLOBALS['dbi']->getRoutines($db, $type);
    echo PMA_RTE_getList('routine', $items);
    /**
     * Display the form for adding a new routine, if the user has the privileges.
     */
    echo PMA_RTN_getFooterLinks();
    /**
     * Display a warning for users with PHP's old "mysql" extension.
     */
    if (!PMA_DatabaseInterface::checkDbExtension('mysqli')) {
        trigger_error(__('You are using PHP\'s deprecated \'mysql\' extension, ' . 'which is not capable of handling multi queries. ' . '[strong]The execution of some stored routines may fail![/strong] ' . 'Please use the improved \'mysqli\' extension to ' . 'avoid any problems.'), E_USER_WARNING);
    }
}
Ejemplo n.º 2
0
/**
 * Main function for the routines functionality
 *
 * @param string $type 'FUNCTION' for functions,
 *                     'PROCEDURE' for procedures,
 *                     null for both
 *
 * @return void
 */
function PMA_RTN_main($type)
{
    global $db;
    PMA_RTN_setGlobals();
    /**
     * Process all requests
     */
    PMA_RTN_handleEditor();
    PMA_RTN_handleExecute();
    PMA_RTN_handleExport();
    /**
     * Display a list of available routines
     */
    $columns = "`SPECIFIC_NAME`, `ROUTINE_NAME`, `ROUTINE_TYPE`, ";
    $columns .= "`DTD_IDENTIFIER`, `ROUTINE_DEFINITION`";
    $where = "ROUTINE_SCHEMA " . PMA_Util::getCollateForIS() . "=" . "'" . PMA_Util::sqlAddSlashes($db) . "'";
    if (PMA_isValid($type, array('FUNCTION', 'PROCEDURE'))) {
        $where .= " AND `ROUTINE_TYPE`='" . $type . "'";
    }
    $items = $GLOBALS['dbi']->fetchResult("SELECT {$columns} FROM `INFORMATION_SCHEMA`.`ROUTINES` WHERE {$where};");
    echo PMA_RTE_getList('routine', $items);
    /**
     * Display the form for adding a new routine, if the user has the privileges.
     */
    echo PMA_RTN_getFooterLinks();
    /**
     * Display a warning for users with PHP's old "mysql" extension.
     */
    if (!PMA_DatabaseInterface::checkDbExtension('mysqli')) {
        trigger_error(__('You are using PHP\'s deprecated \'mysql\' extension, ' . 'which is not capable of handling multi queries. ' . '[strong]The execution of some stored routines may fail![/strong] ' . 'Please use the improved \'mysqli\' extension to ' . 'avoid any problems.'), E_USER_WARNING);
    }
}
 /**
  * Get SQL query for store new transformation details of a VIEW
  *
  * @param object $pma_transformation_data Result set of SQL execution
  * @param array  $column_map              Details of VIEW columns
  * @param string $view_name               Name of the VIEW
  * @param string $db                      Database name of the VIEW
  *
  * @return string $new_transformations_sql SQL query for new transformations
  */
 function getNewTransformationDataSql($pma_transformation_data, $column_map, $view_name, $db)
 {
     $cfgRelation = \PMA_getRelationsParam();
     // Need to store new transformation details for VIEW
     $new_transformations_sql = sprintf("INSERT INTO %s.%s (" . "`db_name`, `table_name`, `column_name`, " . "`comment`, `mimetype`, `transformation`, " . "`transformation_options`) VALUES", \PMA_Util::backquote($cfgRelation['db']), \PMA_Util::backquote($cfgRelation['column_info']));
     $column_count = 0;
     $add_comma = false;
     while ($data_row = $this->dbi->fetchAssoc($pma_transformation_data)) {
         foreach ($column_map as $column) {
             if ($data_row['table_name'] != $column['table_name'] || $data_row['column_name'] != $column['refering_column']) {
                 continue;
             }
             $new_transformations_sql .= sprintf("%s ('%s', '%s', '%s', '%s', '%s', '%s', '%s')", $add_comma ? ', ' : '', $db, $view_name, isset($column['real_column']) ? $column['real_column'] : $column['refering_column'], $data_row['comment'], $data_row['mimetype'], $data_row['transformation'], \PMA_Util::sqlAddSlashes($data_row['transformation_options']));
             $add_comma = true;
             $column_count++;
             break;
         }
         if ($column_count == count($column_map)) {
             break;
         }
     }
     return $column_count > 0 ? $new_transformations_sql : '';
 }
Ejemplo n.º 4
0
    echo '           (' . $mysql_charset_map['utf-8'] . ')' . '        </span>' . '    </li>' . '  </ul>' . ' </div>';
}
if ($GLOBALS['cfg']['ShowServerInfo'] || $GLOBALS['cfg']['ShowPhpInfo']) {
    echo '<div class="group">';
    echo '<h2>' . __('Web server') . '</h2>';
    echo '<ul>';
    if ($GLOBALS['cfg']['ShowServerInfo']) {
        PMA_printListItem($_SERVER['SERVER_SOFTWARE'], 'li_web_server_software');
        if ($server > 0) {
            $client_version_str = $GLOBALS['dbi']->getClientInfo();
            if (preg_match('#\\d+\\.\\d+\\.\\d+#', $client_version_str)) {
                $client_version_str = 'libmysql - ' . $client_version_str;
            }
            PMA_printListItem(__('Database client version:') . ' ' . $client_version_str, 'li_mysql_client_version');
            $php_ext_string = __('PHP extension:') . ' ';
            if (PMA_DatabaseInterface::checkDbExtension('mysqli')) {
                $extension = 'mysqli';
            } else {
                $extension = 'mysql';
            }
            $php_ext_string .= $extension . ' ' . PMA_Util::showPHPDocu('book.' . $extension . '.php');
            PMA_printListItem($php_ext_string, 'li_used_php_extension');
        }
    }
    if ($cfg['ShowPhpInfo']) {
        PMA_printListItem(__('Show PHP information'), 'li_phpinfo', 'phpinfo.php' . $common_url_query, null, '_blank');
    }
    echo '  </ul>';
    echo ' </div>';
}
echo '<div class="group pmagroup">';
 /**
  * Returns the real row count for a table
  *
  * @return number
  */
 function getRealRowCountTable()
 {
     // SQL query to get row count for a table.
     $result = $this->_dbi->fetchSingleRow(sprintf('SELECT COUNT(*) AS %s FROM %s.%s', PMA_Util::backquote('row_count'), PMA_Util::backquote($this->_db_name), PMA_Util::backquote($this->_name)));
     return $result['row_count'];
 }
 /**
  * Handle compatibility options
  *
  * @param PMA_DatabaseInterface $dbi     Database interface
  * @param array                 $request Request array
  *
  * @return void
  */
 private function _setSQLMode($dbi, $request)
 {
     $sql_modes = array();
     if (isset($request['sql_compatibility']) && 'NONE' != $request['sql_compatibility']) {
         $sql_modes[] = $request['sql_compatibility'];
     }
     if (isset($request['sql_no_auto_value_on_zero'])) {
         $sql_modes[] = 'NO_AUTO_VALUE_ON_ZERO';
     }
     if (count($sql_modes) > 0) {
         $dbi->tryQuery('SET SQL_MODE="' . implode(',', $sql_modes) . '"');
     }
 }
Ejemplo n.º 7
0
 /**
  * Test database connection
  *
  * @param string $connect_type 'tcp' or 'socket'
  * @param string $host         host name
  * @param string $port         tcp port to use
  * @param string $socket       socket to use
  * @param string $user         username to use
  * @param string $pass         password to use
  * @param string $error_key    key to use in return array
  *
  * @return bool|array
  */
 public static function testDBConnection($connect_type, $host, $port, $socket, $user, $pass = null, $error_key = 'Server')
 {
     //    static::testPHPErrorMsg();
     $error = null;
     if (PMA_DatabaseInterface::checkDbExtension('mysqli')) {
         $socket = empty($socket) || $connect_type == 'tcp' ? null : $socket;
         $port = empty($port) || $connect_type == 'socket' ? null : $port;
         $extension = 'mysqli';
     } else {
         $socket = empty($socket) || $connect_type == 'tcp' ? null : ':' . ($socket[0] == '/' ? '' : '/') . $socket;
         $port = empty($port) || $connect_type == 'socket' ? null : ':' . $port;
         $extension = 'mysql';
     }
     // dead code (drizzle extension)
     if ($extension == 'drizzle') {
         while (1) {
             $drizzle = @drizzle_create();
             if (!$drizzle) {
                 $error = __('Could not initialize Drizzle connection library!');
                 break;
             }
             $conn = $socket ? @drizzle_con_add_uds($socket, $user, $pass, null, 0) : @drizzle_con_add_tcp($drizzle, $host, $port, $user, $pass, null, 0);
             if (!$conn) {
                 $error = __('Could not connect to the database server!');
                 drizzle_free($drizzle);
                 break;
             }
             // connection object is set up but we have to send some query
             // to actually connect
             $res = @drizzle_query($conn, 'SELECT 1');
             if (!$res) {
                 $error = __('Could not connect to the database server!');
             } else {
                 drizzle_result_free($res);
             }
             drizzle_con_free($conn);
             drizzle_free($drizzle);
             break;
         }
     } else {
         if ($extension == 'mysql') {
             $conn = @mysql_connect($host . $port . $socket, $user, $pass);
             if (!$conn) {
                 $error = __('Could not connect to the database server!');
             } else {
                 mysql_close($conn);
             }
         } else {
             $conn = @mysqli_connect($host, $user, $pass, null, $port, $socket);
             if (!$conn) {
                 $error = __('Could not connect to the database server!');
             } else {
                 mysqli_close($conn);
             }
         }
     }
     //    static::testPHPErrorMsg(false);
     if (isset($php_errormsg)) {
         $error .= " - {$php_errormsg}";
     }
     return is_null($error) ? true : array($error_key => $error);
 }
    /**
     * For testsuite we use dummy driver which can fake some queries.
     */
    include_once './libraries/dbi/DBIDummy.class.php';
    $extension = new PMA_DBI_Dummy();
} else {
    /**
     * First check for the mysqli extension, as it's the one recommended
     * for the MySQL server's version that we support
     */
    $extension = 'mysqli';
    if (!PMA_DatabaseInterface::checkDbExtension($extension)) {
        $docurl = PMA_Util::getDocuLink('faq', 'faqmysql');
        $doclink = sprintf(__('See %sour documentation%s for more information.'), '[a@' . $docurl . '@documentation]', '[/a]');
        $extension = 'mysql';
        if (!PMA_DatabaseInterface::checkDbExtension($extension)) {
            // warn about both extensions missing and exit
            PMA_warnMissingExtension('mysqli|mysql', true, $doclink);
        } elseif (empty($_SESSION['mysqlwarning'])) {
            trigger_error(__('You are using the mysql extension which is deprecated in ' . 'phpMyAdmin. Please consider installing the mysqli ' . 'extension.') . ' ' . $doclink, E_USER_WARNING);
            // tell the user just once per session
            $_SESSION['mysqlwarning'] = true;
        }
    }
    /**
     * Including The DBI Plugin
     */
    switch ($extension) {
        case 'mysql':
            include_once './libraries/dbi/DBIMysql.class.php';
            $extension = new PMA_DBI_Mysql();
Ejemplo n.º 9
0
 /**
  * Function to handle foreign key updates
  *
  * @param array  $destination_foreign_db     destination foreign database
  * @param array  $multi_edit_columns_name    multi edit column names
  * @param array  $destination_foreign_table  destination foreign table
  * @param array  $destination_foreign_column destination foreign column
  * @param array  $options_array              options array
  * @param string $table                      current table
  * @param array  $existrel_foreign           db, table, column
  *
  * @return array
  */
 public function updateForeignKeys($destination_foreign_db, $multi_edit_columns_name, $destination_foreign_table, $destination_foreign_column, $options_array, $table, $existrel_foreign)
 {
     $html_output = '';
     $preview_sql_data = '';
     $display_query = '';
     $seen_error = false;
     foreach ($destination_foreign_db as $master_field_md5 => $foreign_db) {
         $create = false;
         $drop = false;
         // Map the fieldname's md5 back to its real name
         $master_field = $multi_edit_columns_name[$master_field_md5];
         $foreign_table = $destination_foreign_table[$master_field_md5];
         $foreign_field = $destination_foreign_column[$master_field_md5];
         if (isset($existrel_foreign[$master_field_md5]['ref_db_name'])) {
             $ref_db_name = $existrel_foreign[$master_field_md5]['ref_db_name'];
         } else {
             $ref_db_name = $GLOBALS['db'];
         }
         $empty_fields = false;
         foreach ($master_field as $key => $one_field) {
             if (!empty($one_field) && empty($foreign_field[$key]) || empty($one_field) && !empty($foreign_field[$key])) {
                 $empty_fields = true;
             }
             if (empty($one_field) && empty($foreign_field[$key])) {
                 unset($master_field[$key]);
                 unset($foreign_field[$key]);
             }
         }
         if (!empty($foreign_db) && !empty($foreign_table) && !$empty_fields) {
             if (isset($existrel_foreign[$master_field_md5])) {
                 $constraint_name = $existrel_foreign[$master_field_md5]['constraint'];
                 $on_delete = !empty($existrel_foreign[$master_field_md5]['on_delete']) ? $existrel_foreign[$master_field_md5]['on_delete'] : 'RESTRICT';
                 $on_update = !empty($existrel_foreign[$master_field_md5]['on_update']) ? $existrel_foreign[$master_field_md5]['on_update'] : 'RESTRICT';
                 if ($ref_db_name != $foreign_db || $existrel_foreign[$master_field_md5]['ref_table_name'] != $foreign_table || $existrel_foreign[$master_field_md5]['ref_index_list'] != $foreign_field || $existrel_foreign[$master_field_md5]['index_list'] != $master_field || $_REQUEST['constraint_name'][$master_field_md5] != $constraint_name || $_REQUEST['on_delete'][$master_field_md5] != $on_delete || $_REQUEST['on_update'][$master_field_md5] != $on_update) {
                     // another foreign key is already defined for this field
                     // or an option has been changed for ON DELETE or ON UPDATE
                     $drop = true;
                     $create = true;
                 }
                 // end if... else....
             } else {
                 // no key defined for this field(s)
                 $create = true;
             }
         } elseif (isset($existrel_foreign[$master_field_md5])) {
             $drop = true;
         }
         // end if... else....
         $tmp_error_drop = false;
         if ($drop) {
             $drop_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' DROP FOREIGN KEY ' . PMA_Util::backquote($existrel_foreign[$master_field_md5]['constraint']) . ';';
             if (!isset($_REQUEST['preview_sql'])) {
                 $display_query .= $drop_query . "\n";
                 $this->_dbi->tryQuery($drop_query);
                 $tmp_error_drop = $GLOBALS['dbi']->getError();
                 if (!empty($tmp_error_drop)) {
                     $seen_error = true;
                     $html_output .= PMA_Util::mysqlDie($tmp_error_drop, $drop_query, false, '', false);
                     continue;
                 }
             } else {
                 $preview_sql_data .= $drop_query . "\n";
             }
         }
         $tmp_error_create = false;
         if (!$create) {
             continue;
         }
         $create_query = $this->getSQLToCreateForeignKey($table, $master_field, $foreign_db, $foreign_table, $foreign_field, $_REQUEST['constraint_name'][$master_field_md5], $options_array[$_REQUEST['on_delete'][$master_field_md5]], $options_array[$_REQUEST['on_update'][$master_field_md5]]);
         if (!isset($_REQUEST['preview_sql'])) {
             $display_query .= $create_query . "\n";
             $GLOBALS['dbi']->tryQuery($create_query);
             $tmp_error_create = $GLOBALS['dbi']->getError();
             if (!empty($tmp_error_create)) {
                 $seen_error = true;
                 if (substr($tmp_error_create, 1, 4) == '1005') {
                     $message = PMA_Message::error(__('Error creating foreign key on %1$s (check data types)'));
                     $message->addParam(implode(', ', $master_field));
                     $html_output .= $message->getDisplay();
                 } else {
                     $html_output .= PMA_Util::mysqlDie($tmp_error_create, $create_query, false, '', false);
                 }
                 $html_output .= PMA_Util::showMySQLDocu('InnoDB_foreign_key_constraints') . "\n";
             }
         } else {
             $preview_sql_data .= $create_query . "\n";
         }
         // this is an alteration and the old constraint has been dropped
         // without creation of a new one
         if ($drop && $create && empty($tmp_error_drop) && !empty($tmp_error_create)) {
             // a rollback may be better here
             $sql_query_recreate = '# Restoring the dropped constraint...' . "\n";
             $sql_query_recreate .= $this->getSQLToCreateForeignKey($table, $master_field, $existrel_foreign[$master_field_md5]['ref_db_name'], $existrel_foreign[$master_field_md5]['ref_table_name'], $existrel_foreign[$master_field_md5]['ref_index_list'], $existrel_foreign[$master_field_md5]['constraint'], $options_array[$existrel_foreign[$master_field_md5]['on_delete']], $options_array[$existrel_foreign[$master_field_md5]['on_update']]);
             if (!isset($_REQUEST['preview_sql'])) {
                 $display_query .= $sql_query_recreate . "\n";
                 $this->_dbi->tryQuery($sql_query_recreate);
             } else {
                 $preview_sql_data .= $sql_query_recreate;
             }
         }
     }
     // end foreach
     return array($html_output, $preview_sql_data, $display_query, $seen_error);
 }
Ejemplo n.º 10
0
 /**
  * Returns the CREATE statement for this table
  *
  * @return mixed
  */
 public function showCreate()
 {
     return $this->dbi->fetchValue('SHOW CREATE TABLE ' . PMA_Util::backquote($this->db_name) . '.' . PMA_Util::backquote($this->name), 0, 1);
 }
Ejemplo n.º 11
0
 /**
  * Test database connection
  *
  * @param string $connect_type 'tcp' or 'socket'
  * @param string $host         host name
  * @param string $port         tcp port to use
  * @param string $socket       socket to use
  * @param string $user         username to use
  * @param string $pass         password to use
  * @param string $error_key    key to use in return array
  *
  * @return bool|array
  */
 public static function testDBConnection($connect_type, $host, $port, $socket, $user, $pass = null, $error_key = 'Server')
 {
     //    static::testPHPErrorMsg();
     $error = null;
     if (PMA_DatabaseInterface::checkDbExtension('mysqli')) {
         $socket = empty($socket) || $connect_type == 'tcp' ? null : $socket;
         $port = empty($port) || $connect_type == 'socket' ? null : $port;
         $extension = 'mysqli';
     } else {
         $socket = empty($socket) || $connect_type == 'tcp' ? null : ':' . ($socket[0] == '/' ? '' : '/') . $socket;
         $port = empty($port) || $connect_type == 'socket' ? null : ':' . $port;
         $extension = 'mysql';
     }
     if ($extension == 'mysql') {
         $conn = @mysql_connect($host . $port . $socket, $user, $pass);
         if (!$conn) {
             $error = __('Could not connect to the database server!');
         } else {
             mysql_close($conn);
         }
     } else {
         $conn = @mysqli_connect($host, $user, $pass, null, $port, $socket);
         if (!$conn) {
             $error = __('Could not connect to the database server!');
         } else {
             mysqli_close($conn);
         }
     }
     //    static::testPHPErrorMsg(false);
     if (isset($php_errormsg)) {
         $error .= " - {$php_errormsg}";
     }
     return is_null($error) ? true : array($error_key => $error);
 }
Ejemplo n.º 12
0
 if (!PMA_DatabaseInterface::checkDbExtension($extensionName)) {
     // if it fails try alternative extension ...
     // and display an error ...
     $docurl = PMA_Util::getDocuLink('faq', 'faqmysql');
     $doclink = sprintf(__('See %sour documentation%s for more information.'), '[a@' . $docurl . '@documentation]', '[/a]');
     /**
      * @todo add different messages for alternative extension
      * and complete fail (no alternative extension too)
      */
     PMA_warnMissingExtension($extensionName, false, $doclink);
     if ($extensionName === 'mysql') {
         $alternativ_extension = 'mysqli';
     } else {
         $alternativ_extension = 'mysql';
     }
     if (!PMA_DatabaseInterface::checkDbExtension($alternativ_extension)) {
         // if alternative fails too ...
         PMA_warnMissingExtension($extensionName, true, $doclink);
     }
     $GLOBALS['cfg']['Server']['extension'] = $alternativ_extension;
     unset($alternativ_extension);
 }
 /**
  * Including The DBI Plugin
  */
 switch ($GLOBALS['cfg']['Server']['extension']) {
     case 'mysql':
         include_once './libraries/dbi/DBIMysql.class.php';
         $extension = new PMA_DBI_Mysql();
         break;
     case 'mysqli':