$referer = $_SERVER[HTTP_REFERER];
 
if($referer)
{
    preg_match("/[\&\?]q=([^&]*)/", $referer, $matches);
 
    if($matches[1])
    {
        $search_query = rawurldecode($matches[1]);
        $search_query = str_replace("+", " ", $search_query);
        mysql_query("INSERT INTO google_referrer (id, search_query) VALUES ('', '$search_query')");
    }
}
Veritabanına yazdırma kısmını örnek olarak yazdım. Tablo yapın nasıl ise ona göre ayarlarsın. Kolay gelsin.