Jump to content

[SOLVED] local variables not holding their values after recordset closes


rwiltfon

Recommended Posts

Hello,

I am a newbie to PHP, and have run across a puzzling problem.  I have the following script:

 

************************************************************************

<?php

 

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

or die("Cannot start ADO");

 

//define connection string, specify database driver

$connStr = [connection string supressed];

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

 

$sql = "SELECT * FROM portal.dbo.portal_setup WHERE strServerName = '" . $_SERVER['HTTP_HOST'] . "'";

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

if (!$rs->EOF) {

$strPortal = $rs["strPortal"];

}

echo "x. " . $strPortal . "<BR>";

$rs->close();

echo "y. " . $strPortal . "<BR>";

 

?>

***************************************************************************

And I get the following error:

Catchable fatal error: Object of class variant could not be converted to string

 

it's happening on echo "y. " . $strPortal . "<BR>"; after I close the recordset

 

I'm getting records back, because when I echo "x. " . $strPortal . "<BR>"; the value is there.  So it seems to be that there is a pointer to the record within the recordset which I don't want.  I want the local variable to hold the value of the record so I can close the recordset and just use the local variable in other parts of the page.  Any suggestions would be most welcome!  Thank you.

Link to comment
Share on other sites

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.