Jump to content

SQLSRV Connection question


johnson.sh

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/244257-sqlsrv-connection-question/
Share on other sites

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

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.