如何在php中使用数据库重写URL

I have little knowledge of .htaccess file and able to rewrite url. but for huge number of pages and page specific url requirements, i can't define this in .htaccess file. I had to use database for storing different urls of different pages, now i don't have any idea how to use it. I know working of dynamic url rewriting also like rewriting following url

www.mysite.com/garments/news.php?id=32

to

www.mysite.com/garments/news/32

but what about random page urls like

www.mysite.com/garments/news.php

to

www.mysite.com/latest-news

To get this link i would use this:

RewriteEngine On
RewriteRule    ^latest-news/([0-9]+)/?$    garments/news.php?id=$1

What this does is redirect this url:

www.mysite.com/latest-news/30/

to this:

www.mysite.com/garments/news.php?id=30