mysql has an AUTO_INCREMENT attribute that can be used for this very purpose. Just declare your customer id field to be of type INT PRIMARY KEY AUTO_INCREMENT. If you insert NULL into that field, mysql will assign a unique id for that row, and you can retrieve the id using the LAST_INSERT_ID() function.