Habari\DatabaseConnection::execute_procedure PHP Метод

execute_procedure() публичный Метод

Execute a stored procedure
public execute_procedure ( string $procedure, array $args = [] ) : mixed
$procedure string name of the stored procedure
$args array arguments for the procedure
Результат mixed whatever the procedure returns...
    public function execute_procedure($procedure, $args = array())
    {
        /* Local scope caching */
        $pdo = $this->pdo;
        $pdo_statement = $this->pdo_statement;
        if ($pdo_statement != null) {
            $pdo_statement->closeCursor();
        }
        $query = 'CALL ' . $procedure . '( ';
        if (count($args) > 0) {
            $query .= str_repeat('?,', count($args));
            // Add the placeholders
            $query = substr($query, 0, strlen($query) - 1);
            // Strip the last comma
        }
        $query .= ' )';
        $query = $this->sql_t($query, $args);
        if ($pdo_statement = $pdo->prepare($query)) {
            /* If we are profiling, then time the query */
            if ($this->keep_profile) {
                $profile = new QueryProfile($query);
                $profile->start();
            }
            if (!$pdo_statement->execute($args)) {
                $this->add_error(array('query' => $query, 'error' => $pdo_statement->errorInfo()));
                return false;
            }
            if ($this->keep_profile) {
                $profile->stop();
                $this->profiles[] = $profile;
            }
            return true;
        } else {
            $this->add_error(array('query' => $query, 'error' => $pdo_statement->errorInfo()));
            return false;
        }
    }