While using ajax based dropdowns, I required a db connection in php page (non joomla page). I did it as follows:
include(“../../../../configuration.php”); //adjust the path of configuration.php
$config = new JConfig();
$con = mysql_connect($config->host,$config->user,$config->password);
And Thats it 🙂
Same goes with almost every cms and framework.