user1358065
user1358065

Reputation: 103

Connecting to MSSQL database with ADO and PHP

I have a MSSQL database. I wrote a php page to connect and retreive data from it. The code works on my localhost.

$strCon = "Provider=SQLOLEDB;Data Source=local;database=test;uid=sa;pwd=go;";

$strAlias = "GEORGE";

$strSql = "SELECT LINK FROM LINKS WHERE ALIAS = '" . $strAlias . "'";

$Con = new COM ("ADODB.Connection") or die("Cannot start ADO");
$Rs = new COM ("ADODB.Recordset") or die("Cannot start ADO");
$Con->open($strCon);
$Rs->open($strSql,$Con,1,3);

if (!$Rs->EOF && !$Rs->BOF) {
 $strTargetLink = $Rs->Fields['LINK'];
 echo $strTargetLink;
}

$Rs->Close();
$Con->Close();
$Rs = null;
$Con = null;

When I run this code on the server, I receive some error? when echo $strTargetLink; row is executed, word

Object

is received on the sent html page and also in the source code of that page.

I am running PHP on IIS as a FastCGI application. Both PHP 4.4.7 and 5.2.6 are supported.

Any ideas? What does this Object text mean?

Thanks.

Instead of using echo, I now tried

var_dump($strTargetLink);

and received the information

object(COM)(1) { [0]=> resource(3) of type (COM) }

Upvotes: 0

Views: 1801

Answers (2)

user1358065
user1358065

Reputation: 103

I have found a solution and now it works. So just in case you would like to connect with ADO, I am writing what I have done.

Instead of

$strTargetLink = $Rs->Fields['LINK']; 

I wrote

$strTargetLink = $Rs->Fields(0);

Upvotes: 0

nathan gonzalez
nathan gonzalez

Reputation: 11987

try using var_dump instead of echo. it will at least give you more information about the object contained in $strTargetLink.

Upvotes: 0

Related Questions