Well you'll need to find a way to get the short code SMS to communicate with your PHP script. I have no idea how to do this. When it comes to the PHP, it seems easy enough.
switch(strtolower($_GET['command'])) {
case 'pizza':
$r = mysql_query("SELECT * FROM pizza ORDER BY popularity DESC LIMIT 5");
if(mysql_num_rows($r) != 0) {
while($arr = mysql_fetch_array($r)) { echo $arr['name']; }
} else { echo "No pizzas found. Sry!"; }
break;
}
This would work assuming you have already connected to your database and your table structure is similar to my little demo. You would also need to have texts to the number routed to your script, assuming the command parameter contains the contents of the text and the stdout is returned to the sender of the text message.