You can use:
SELECT COUNT(id)+1 as IDCount FROM donations
as your request. This will save you from any errors in PHP to do the math. The array you are retreating from will have the number you want right off the bat.
Edit: The best alternative, however, is to use a column type that automatically grows. In MySQL, this is done with the auto_increment syntax in the create table syntax.
Using this, you never need to insert a value, but you pass it NULL as follows (assuming the identifier is a field with Auto_increment on it:
insert into tableName (ID,Name) values (null, 'Fluffeh');
So, you see that you are not giving it any values ββfor the ID column - the database takes care of the correct number.
source share