If it was in access, I would rewrite certificate_generate_code().
There are two tables: certificate and certificate_issues. Initially, I would not edit the function certificate_get_code in locallib.php. I believe you want to edit the locallib.php file's function certificate_generate_code().
To generate the next sequential number using Access, I would do a countif of the certificate id in the certificate_issues table. If the count was zero, then I would assign it the starting number, say 1001, else add the count+1001 and put that as a string variable called "nextnumber". Basically the new "code" is the customtext field from the matching id in the certificate table and "nextnumber" as the new code string. This should be a unique string.
Again, I do not program in php. I would be playing around on a localhost.
Did you try something like the above.