My problem is how to combine the program of the RFID reader and the GSM shield to arduino Mega
Specifically, what is the problem?
That method for reading the serial response is junk. Aside from that, what IS the problem?
You have a sketch that can, apparently, send text messages. You have a sketch that can, apparently, read RFID tags. Combining them to send a text message containing an RFID tag is trivial.
All you need to do then is to create an application that you can send a text message to that can access the database and generate a reply.
Then, when you get the crappy readSerialString() function working usefully, you can do something with the response.
I'd say that right now you have about 2 of the 10 pieces of code written that you need.