I am creating a php restful API and currently I have the database connection information in each function.
//Connect To Database
$hostname=host;
$use
Why won't you move out the connection information into config and the call to mysql_connect into some factory?
E.g.
class ConnectionFactory {
public static MysqlConnection CreateConnection() {
$connection = mysql_connect(Config::$host, Config::$port etc);
mysql_select_db($connection, Config::$schema);
return $connection;
}
}
and then in your code
$connection = ConnectionFactory::CreateConnection();
mysql_query($connection, $sqlApiAccess) or die('Error, insert query failed');