$mysqli->info is null after successful insert of single row
mysql, mysqli, php
Solution
http://dev.mysql.com/doc/apis-php/en/apis-php-mysqli.info.html
Table 3.9 Possible mysqli_info return values
Query Type - Example result string
- INSERT INTO...SELECT... Records: 100 Duplicates: 0 Warnings: 0
- INSERT INTO...VALUES (...),(...),(...) Records: 3 Duplicates: 0 Warnings: 0
- LOAD DATA INFILE ... Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
- ALTER TABLE ... Records: 3 Duplicates: 0 Warnings: 0
- UPDATE ... Rows matched: 40 Changed: 40 Warnings: 0
Note
Queries which do not fall into one of the preceding formats are not supported. In these situations, mysqli_info will return an empty string.
Conclusion: There is not a case listed above for a single row insert. Therefore, an empty string is what should be expected.
Problem
After inserting multiple rows with a single insert statement, I get expected behavior from $mysqli->info. ``` var_dump( $mysqli->info ); string 'Records: 1246 Duplicates: 0 Warnings: 0' (length=41) ``` After inserting a single row, $mysqli->info returns NULL ``` var_dump( $mysqli->info ); null var_dump( $mysqli->affected_rows ); int 1 ``` mysqli_info() returns an empty string ``` var_dump( mysqli_info( $mysqli ) ) string '' (length=0) ``` I cannot find any reference to this behavior! I would expect info after a single insert like ``` string 'Records: 1 Duplicates: 0 Warnings: 0' (length=38) ``` PHP 5.4.12, mySQL 5.6.12 Executed Code: ``` $sql = "INSERT INTO module_history (BackupDate, Modules) VALUES ('2014-01-01','Module List1')"; $db->query($sql); echo $sql . "\n"; var_dump( $db->info ); var_dump( $db->affected_rows ); $sql = "INSERT INTO module_history (BackupDate, Modules) VALUES ('2014-01-02','Module List2'),('2014-01-03','Module List3')"; $db->query($sql); echo $sql . "\n"; var_dump( $db->info ); var_dump( $db->affected_rows ); ``` Results: ``` INSERT INTO module_history (BackupDate, Modules) VALUES ('2014-01-01','Module List1') null int 1 INSERT INTO module_history (BackupDate, Modules) VALUES ('2014-01-02','Module List2'),('2014-01-03','Module List3') string 'Records: 2 Duplicates: 0 Warnings: 0' (length=38) int 2 ```