Page 1 of 1

Connection Function/Class

Posted: Fri Apr 13, 2012 10:41 am
by markyboy17
Below is how i am connecting to my database. I do this on every page.

Code: Select all

 
$cdatabase = 'XXXXXXX;
$cUID = 'XXXXXX';
$cPWD = 'XXXXXX';
$cSRVname = 'XXXXXXX';
$cconnectionInfo = array("Database" => $cdatabase, "UID" => $cUID, "PWD" => $cPWD);
$cconn = sqlsrv_connect($cSRVname, $cconnectionInfo);
My question is how do make this into a function of some sorts. And how do i call it on each page

BTW i will be using the variable $cconn when i do queries and things how would i make it so this variable is accessible to use on every page (i.e Make it a global variable)

Thanks in advance

Re: Connection Function/Class

Posted: Fri Apr 13, 2012 10:44 am
by Celauran
Rather than creating a new class, use the excellent PDO.