rwiltfon Posted January 30, 2008 Share Posted January 30, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/88635-solved-local-variables-not-holding-their-values-after-recordset-closes/ Share on other sites More sharing options...
Barand Posted January 31, 2008 Share Posted January 31, 2008 try $strPortal = (string)$rs["strPortal"]; Quote Link to comment https://forums.phpfreaks.com/topic/88635-solved-local-variables-not-holding-their-values-after-recordset-closes/#findComment-454008 Share on other sites More sharing options...
rwiltfon Posted January 31, 2008 Author Share Posted January 31, 2008 yes! that did it -- I also found that $strPortal = sprintf($rs["strPortal"]); worked too. It doesn't do any null handling, so I'll probably create a function to do that. Thanks so much for the help! Quote Link to comment https://forums.phpfreaks.com/topic/88635-solved-local-variables-not-holding-their-values-after-recordset-closes/#findComment-454405 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.