I have this table:
CREATE TABLE `test` (
`Id1` int(11) unsigned NOT NULL,
`Id2` int(11) unsigned NOT NULL,
`Id3` int(11) unsigned NOT NULL,
`Id4` int(11) unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(255) NOT NULL,
PRIMARY KEY (`Id1`,`Id2`,`Id3`,`Id4`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
INSERT INTO `test` (`Id1`, `Id2`, `Id3`, `Name`) VALUES (1, 1, 1, 'test')
INSERT INTO `test` (`Id1`, `Id2`, `Id3`, `Name`) VALUES (1, 1, 1, 'test2')
INSERT INTO `test` (`Id1`, `Id2`, `Id3`, `Name`) VALUES (1, 2, 1, 'test')
INSERT INTO `test` (`Id1`, `Id2`, `Id3`, `Name`) VALUES (1, 2, 1, 'test2')
After creating the table the date looks like this:
Id1 Id2 Id3 Id4 Name
1 1 1 1 test
1 1 1 2 test2
1 2 1 1 test
1 2 1 2 test2
Id4 is incrementing as is expected but I have problem to get inserted Id4 using PHP mysqli. This is the code I am using:
$db = new mysqli('host', 'user', 'pass', 'db');
$db->query("INSERT INTO `test` (`Id1`, `Id2`, `Id3`, `Name`) VALUES (1, 1, 1, 'test')");
var_dump($db->insert_id);
I get result
int(0)
Result should be int(1)
but I get zero for no reason. Any ideas?