Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

pdo

flightphp

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();
?>
like image 887
Hamidreza Ghaffari Avatar asked Sep 01 '14 07:09

Hamidreza Ghaffari


1 Answers

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.

like image 124
Hamidreza Ghaffari Avatar answered Oct 03 '22 01:10

Hamidreza Ghaffari