Mysql query repeated

Hi, in my controller I have a query

        $projects = Project::query()
        ->where('active = :active:')
        ->bind(['active' => 0])
        ->order('created_at desc')
        ->execute();

Then I have a query logger which looks like

    $logger = new FileLogger("../app/logs/debug.log");

    //Listen all the database events
    $eventsManager->attach('db', function($event, $connection) use ($logger) {
        if ($event->getType() == 'beforeQuery') {
            $logger->log($connection->getSQLStatement(), Logger::INFO);
        }
    });

Now, on each request I can see that this project query is generated 3 times?

[Sun, 16 Nov 14 10:54:22 +0000][INFO] SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`='Projects'
[Sun, 16 Nov 14 10:54:22 +0000][INFO] DESCRIBE `Projects`
[Sun, 16 Nov 14 10:54:22 +0000][INFO] SELECT `Projects`.`id`, `Projects`.`name`, `Projects`.`url`, `Projects`.`description`, `Projects`.`email`, `Projects`.`active`, `Projects`.`created_at` FROM `Projects` WHERE `Projects`.`active` = :active ORDER BY `Projects`.`created_at` DESC

[Sun, 16 Nov 14 10:54:22 +0000][INFO] SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`='Projects'
[Sun, 16 Nov 14 10:54:22 +0000][INFO] DESCRIBE `Projects`
[Sun, 16 Nov 14 10:54:22 +0000][INFO] SELECT `Projects`.`id`, `Projects`.`name`, `Projects`.`url`, `Projects`.`description`, `Projects`.`email`, `Projects`.`active`, `Projects`.`created_at` FROM `Projects` WHERE `Projects`.`active` = :active ORDER BY `Projects`.`created_at` DESC

[Sun, 16 Nov 14 10:54:22 +0000][INFO] SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`='Projects'
[Sun, 16 Nov 14 10:54:22 +0000][INFO] DESCRIBE `Projects`
[Sun, 16 Nov 14 10:54:22 +0000][INFO] SELECT `Projects`.`id`, `Projects`.`name`, `Projects`.`url`, `Projects`.`description`, `Projects`.`email`, `Projects`.`active`, `Projects`.`created_at` FROM `Projects` WHERE `Projects`.`active` = :active ORDER BY `Projects`.`created_at` DESC

What am I doing wrong? Why is this getting generated 3 times? Shouldn't it be only 1 time?



5.9k

You test it in browser?

I have experienced before it was browser issue it make request 2 times.

try run your script via php cli or different browser