johnson.sh Posted August 8, 2011 Share Posted August 8, 2011 Hi there! I'm trying to update my project to work with the new MS SQLSRV driver. I've installed the driver and it works ok. Before the MS driver i had a connection to the sql server (connect.php) and included it on every page. Now, i'm trying to do the same but some commands, i.e SQLSRV_QUERY require the $conn (connection resource) as a parameter. That resource cannot be passed from the connect.php (or maybe i don't know how to do it properly). So my question is - Do i need to connect again using SQLSRV_CONNECT on every page? My setup: WAMP 2.1, MSSQL 2008 @ WIN Server 2008 Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/244257-sqlsrv-connection-question/ Share on other sites More sharing options...
requinix Posted August 8, 2011 Share Posted August 8, 2011 If you're include()ing the connect.php on every page you need it then you can return the connection from it. Just use the return keyword from within the file. // $connection = whatever you do to connect return $connection; Then you can grab it when you include() the file. $conn = include "connect.php"; Note that there are other answers. I think this will be the easiest change for you. Quote Link to comment https://forums.phpfreaks.com/topic/244257-sqlsrv-connection-question/#findComment-1254535 Share on other sites More sharing options...
johnson.sh Posted August 11, 2011 Author Share Posted August 11, 2011 If you're include()ing the connect.php on every page you need it then you can return the connection from it. Just use the return keyword from within the file. <?php // $connection = whatever you do to connect return $connection; Then you can grab it when you include() the file. $conn = include "connect.php"; Note that there are other answers. I think this will be the easiest change for you. Thanks, that worked great for me! Quote Link to comment https://forums.phpfreaks.com/topic/244257-sqlsrv-connection-question/#findComment-1255803 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.