I
I
Igor Braduloff2018-09-17 10:54:25
SQL
Igor Braduloff, 2018-09-17 10:54:25

How to correctly select the data for the year from the procedure?

Good afternoon! Tell me how to choose the correct reporting data for the year, not load the server and build a graph in Yii2? My process is very slow

$year = '2018'; // todo: get $year
            $records = [];
            for ($i = 1; $i <= 12; $i++) {
                $m = $i < 10 ? "0{$i}" : $i;
                $firstDay = date("Y-{$m}-01 00:00:00", strtotime("{$year}-{$m}-01"));
                $lastDay = date("Y-{$m}-t 23:59:59", strtotime("{$year}-{$m}-01"));

                $command1 = Yii::$app->db->createCommand("EXEC sp_GetRecipientPaymentsGroupedByServices @user = :p_user, @sd= :p_start, @ed= :p_end");
                $command1->bindParam(":p_user", $user, PDO::PARAM_INT);
                $command1->bindParam(":p_start", $firstDay, PDO::PARAM_STR);
                $command1->bindParam(":p_end", $lastDay, PDO::PARAM_STR);
                $records[] = $command1->queryAll();
            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-09-17
@webinar

Tell me how to choose

Remove the cycle, at least remove the request from the cycle, so that there is 1 request, and not 12.
And what does yii have to do with it? Here the question is more in the sql plane (msSql) or, in extreme cases, php, as I understand it, the difficulty in building a query, and not in the yii methods that you use.
Not strong in msSql, but I'm sure that you can select a year without sorting through the months: https://yandex.ru/search/?text=ms%20sql%20%D0%B2%D...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question