byenary Posted September 29, 2014 Share Posted September 29, 2014 HI, i'm using a class to create a database connection etc.. So I have something like this in a common.inc.php file which is include in each page $db_numbers_args = array();$db_numbers_args['host'] = "localhost";$db_numbers_args['user'] = "puser";$db_numbers_args['pass'] = "nuser";$db_numbers_args['db'] = "nu_name";$db_numbers = new db($db_numbers_args,TRUE); From there I can end up making query's like $res = $db_numbers->query($uqs); So that said i'm including another file that contains all functions, when the functions need to do database transactions I always need to put $db_numbers as a paramter to the function and each function I make.. How should I make this better ? Quote Link to comment https://forums.phpfreaks.com/topic/291356-prevent-database-connection-as-a-parameter-to-all-function/ Share on other sites More sharing options...
Psycho Posted September 29, 2014 Share Posted September 29, 2014 You could use a singleton factory. Take a look at the first response here: http://stackoverflow.com/questions/130878/global-or-singleton-for-database-connection Quote Link to comment https://forums.phpfreaks.com/topic/291356-prevent-database-connection-as-a-parameter-to-all-function/#findComment-1492418 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.