fivestringsurf Posted December 5, 2013 Share Posted December 5, 2013 I can't seem to get reliable results after deleting a row(s) using mysqli. The afftect_rows is always 0. I'm using php5.2 and the mysqli method Something like this: $sql = " DELETE FROM classRoster WHERE id=123 "; if ($result = $this->mysqli->query($sql)) { return $this->mysqli->affected_rows; ///ALWAYS RETURNS 0 }else{ //log error } I have confirmed that the row is in fact deleted, but still get 0 as affected_rows. Please help! Quote Link to comment https://forums.phpfreaks.com/topic/284557-get-affected-rows-after-delete-mysql/ Share on other sites More sharing options...
mac_gyver Posted December 5, 2013 Share Posted December 5, 2013 (edited) i have seen (past) cases with mysql/mysqli functions where using them in a return statement returns null (which would be treated as a zero.) you can try to assign the value to a variable, then return that variable. also, it's possible that your page is being requested twice by your browser and/or a redirect and you are seeing the result of the second page request, which would be a zero since the row would have been deleted on the first page request. you could run a select query before trying to delete it to insure it exists. this would at least get your code to tell you if it has previously been deleted. Edited December 5, 2013 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/284557-get-affected-rows-after-delete-mysql/#findComment-1461384 Share on other sites More sharing options...
Solution fivestringsurf Posted December 10, 2013 Author Solution Share Posted December 10, 2013 Curiously the problem solved itself after a reboot. I'm running xammp on windows 7 on a laptop and I get alot of weird inconsistencies like this when I change table structures and then run queries with php. I find I have to restart MySQL after adding table columns or they don't get recognized from php but do with phpMyAdmin. It's strange as I never encounter these problems when using MySQL/php on my mac or production linux server. I'll just assume it's some low-level installation glitch within xampp that I'll probably never get to the bottom of. Quote Link to comment https://forums.phpfreaks.com/topic/284557-get-affected-rows-after-delete-mysql/#findComment-1461999 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.