Jump to content

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.

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.