PHP-MySQLi-Database-Class icon indicating copy to clipboard operation
PHP-MySQLi-Database-Class copied to clipboard

Get id of the last updated row ?

Open maan81 opened this issue 4 years ago • 2 comments

I was looking as this https://stackoverflow.com/questions/1388025/how-to-get-id-of-the-last-updated-row-in-mysql#answer-1751282 . How to execute it ?

I have done :

    $sql = 'SET @scanning_id := 0;'.
            'UPDATE mytable '.
            'SET status = "true", '.
            'id = (SELECT @scanning_id := id) '.
            'WHERE param = "asdf" LIMIT 1; '.
            'SELECT @scanning_id;';

    $id = $db->rawQuery($sql);

I get the error :

    PHP Fatal error:  Uncaught Exception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE mytable SET status = "true", id = (SELECT @scanning_id := id) WHERE hr' at line 1 query: SET @id := 0; UPDATE mytable SET status = "true", id = (SELECT @scanning_id := id) WHERE params = "asdf" LIMIT 1; SELECT @scanning_id; in PHP_MySQLi_Database/MysqliDb.php:2006

maan81 avatar Oct 10 '20 09:10 maan81

Is it possible to run raw unprepared queries ?

maan81 avatar Oct 10 '20 09:10 maan81

Only method insert() can return last_id. method update() only return status update (check is: "$db->count" )

kythuatwebso avatar Oct 14 '20 03:10 kythuatwebso