Jump to content

Recommended Posts

Hi All,

 

I am in the middle of a migration project, where I have to migrate all my Linux based MySQL databases to a Windows based MS SQL 2005 Express.

I have one IIS 6.0 webserver and one SQL 2005 Express server (2 boxes). I have verified that I can create an ODBC connection to the SQL server (to verify the SQL server configuration).

 

I run into trouble as soon as I try to connect to the MS SQL server via PHP.

Source code:

<?php

$connection = mssql_connect("TW-SQL01","test","test");

echo "connected";

?>

 

The last line is just to verify that my script is not stuck somewhere. Unfortunately the script is stuck which the first line.

 

I have the mssql extension enabled (verified in phpinfo()).

 

Any help will be appriciated.

i believe it has something to do with the permissions that are being passed. i am having a similar problem where my DNS connection looks good but then does not connect from the script. i can even run the script from the command line and it works. but at that point i am logged on as the admin so all permissions are open. i know this doesn't solve your problem, but maybe with two heads pointing in the same direction we can come up with a solution.

 

Bill

again this is not an answer to your question, but rather the work around that i used up for my situation. i could not figure out the permissions part of it (at some point i will). here is the script that i used. this was the only way i could connect to my remote server. i really hope this helps. the script basically connects and then lists out the contents (so choose a small table). -- Bill

 

<?php

$myServer = "SERVER (or 'localhost')";

$myUser = "yourUser";

$myPass = "yourPass";

$myDB = "yourDB";

 

//create an instance of the  ADO connection object

$conn = new COM ("ADODB.Connection")

  or die("Cannot start ADO");

 

//define connection string, specify database driver

$connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB;

  $conn->open($connStr); //Open the connection to the database

 

//declare the SQL statement that will query the database

$query = "SELECT * FROM yourTable";

 

//execute the SQL statement and return records

$rs = $conn->execute($query);

 

$num_columns = $rs->Fields->Count();

echo $num_columns . "<br>";

 

for ($i=0; $i < $num_columns; $i++) {

    $fld[$i] = $rs->Fields($i);

}

 

echo "<table>";

 

while (!$rs->EOF)  //carry on looping through while there are records

{

    echo "<tr>";

    for ($i=0; $i < $num_columns; $i++) {

        echo "<td>" . $fld[$i]->value . "</td>";

    }

    echo "</tr>";

    $rs->MoveNext(); //move on to the next record

}

 

 

echo "</table>";

 

//close the connection and recordset objects freeing up resources

$rs->Close();

$conn->Close();

 

$rs = null;

$conn = null;

?>

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.