PDO : insert 3 rows instead in mysql when i insert just 1 row

968 views Asked by At

I use PDO in my php framework (flight) and i have a ridiculous problem. When i insert 1 row into the mysql i saw 3 rows inserted .

Flight::db()->query("INSERT INTO `menu_item`(`order`, `menu_cat_id`) VALUES (22,1)");

This is My whole code :

<?php
require 'flight/Flight.php';

Flight::register('db', 'PDO', array('mysql:host=localhost;port=3306;dbname=deliman', 'root', ''), function($db) {
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
        $db->exec("SET NAMES 'utf8';");
        $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
});

Flight::route('/menu/item/new', function(){
        //$conn = Flight::db();
        $data = Flight::db()->query("INSERT INTO `menu_item`(`order`, `menu_cat_id`) VALUES (22,1)");

        //SET @maxOrder := (SELECT `order` FROM `menu_item` WHERE `menu_cat_id` = 1 ORDER BY `order` DESC LIMIT 1) +1 ;
        //SELECT LAST_INSERT_ID() AS id;
        echo 'a';
    });


Flight::start();
?>
1

There are 1 answers

0
Hamidreza Ghaffari On BEST ANSWER

i find my answer in this post . pdo insert two rows when I wanna insert only one

So when i test in my browser , it send multiple request and every time my code running . That's it.