The documentation for Twilio SMS responses is here:
https://www.twilio.com/docs/api/twiml/sms/twilio_request
Here is a relevant quote:
When Twilio receives a message for one of your Twilio numbers it makes
  a synchronous HTTP request to the message URL configured for that
  number, and expects to receive TwiML in response. Twilio sends the
  following parameters with its request as POST parameters or URL query
  parameters, depending on which HTTP method you've configured.
You should simply have the data fields inside of PHP's $_REQUEST[] variable.
$_REQUEST['MessageSid'] -  A 34 character unique identifier for the message. May be used to later retrieve this message from the REST API.
$_REQUEST['SmsSid'] -  Same value as MessageSid. Deprecated and included for backward compatibility.
$_REQUEST['AccountSid'] -  The 34 character id of the Account this message is associated with.
$_REQUEST['From'] -  The phone number that sent this message.
$_REQUEST['To'] -  The phone number of the recipient.
$_REQUEST['Body'] -  The text body of the message. Up to 1600 characters long.
$_REQUEST['NumMedia'] -  The number of media items associated with your message
Here is an example query you might use with a MySQL database. You should also be sending back a proper TWIXML response to Twilio and scrub the received data before running a query like this. 
$sql = "INSERT INTO messages (sid, from, body) 
        VALUES (
                 '".$_REQUEST['MessageSid']."',
                 '".$_REQUEST['From']."',
                 '".$_REQUEST['Body']."'
               )";