PMA\libraries\DatabaseInterface::getRoutines PHP Méthode

getRoutines() public méthode

returns details about the PROCEDUREs or FUNCTIONs for a specific database or details about a specific routine
public getRoutines ( string $db, string $which = null, string $name = '' ) : array
$db string db name
$which string PROCEDURE | FUNCTION or null for both
$name string name of the routine (to fetch a specific routine)
Résultat array information about ROCEDUREs or FUNCTIONs
    public function getRoutines($db, $which = null, $name = '')
    {
        $routines = array();
        if (!$GLOBALS['cfg']['Server']['DisableIS']) {
            $query = "SELECT" . " `ROUTINE_SCHEMA` AS `Db`," . " `SPECIFIC_NAME` AS `Name`," . " `ROUTINE_TYPE` AS `Type`," . " `DEFINER` AS `Definer`," . " `LAST_ALTERED` AS `Modified`," . " `CREATED` AS `Created`," . " `SECURITY_TYPE` AS `Security_type`," . " `ROUTINE_COMMENT` AS `Comment`," . " `CHARACTER_SET_CLIENT` AS `character_set_client`," . " `COLLATION_CONNECTION` AS `collation_connection`," . " `DATABASE_COLLATION` AS `Database Collation`," . " `DTD_IDENTIFIER`" . " FROM `information_schema`.`ROUTINES`" . " WHERE `ROUTINE_SCHEMA` " . Util::getCollateForIS() . " = '" . $GLOBALS['dbi']->escapeString($db) . "'";
            if (PMA_isValid($which, array('FUNCTION', 'PROCEDURE'))) {
                $query .= " AND `ROUTINE_TYPE` = '" . $which . "'";
            }
            if (!empty($name)) {
                $query .= " AND `SPECIFIC_NAME`" . " = '" . $GLOBALS['dbi']->escapeString($name) . "'";
            }
            $result = $this->fetchResult($query);
            if (!empty($result)) {
                $routines = $result;
            }
        } else {
            if ($which == 'FUNCTION' || $which == null) {
                $query = "SHOW FUNCTION STATUS" . " WHERE `Db` = '" . $GLOBALS['dbi']->escapeString($db) . "'";
                if (!empty($name)) {
                    $query .= " AND `Name` = '" . $GLOBALS['dbi']->escapeString($name) . "'";
                }
                $result = $this->fetchResult($query);
                if (!empty($result)) {
                    $routines = array_merge($routines, $result);
                }
            }
            if ($which == 'PROCEDURE' || $which == null) {
                $query = "SHOW PROCEDURE STATUS" . " WHERE `Db` = '" . $GLOBALS['dbi']->escapeString($db) . "'";
                if (!empty($name)) {
                    $query .= " AND `Name` = '" . $GLOBALS['dbi']->escapeString($name) . "'";
                }
                $result = $this->fetchResult($query);
                if (!empty($result)) {
                    $routines = array_merge($routines, $result);
                }
            }
        }
        $ret = array();
        foreach ($routines as $routine) {
            $one_result = array();
            $one_result['db'] = $routine['Db'];
            $one_result['name'] = $routine['Name'];
            $one_result['type'] = $routine['Type'];
            $one_result['definer'] = $routine['Definer'];
            $one_result['returns'] = isset($routine['DTD_IDENTIFIER']) ? $routine['DTD_IDENTIFIER'] : "";
            $ret[] = $one_result;
        }
        // Sort results by name
        $name = array();
        foreach ($ret as $value) {
            $name[] = $value['name'];
        }
        array_multisort($name, SORT_ASC, $ret);
        return $ret;
    }