fred12ned Posted January 24, 2007 Share Posted January 24, 2007 I get this error: Object of class variant could not be converted to stringand i don't know why[code]<?phpclass conn{ var $db; function connect($dbname){ $this->db = new COM("ADODB.Connection"); $connstr = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=". realpath("./".$dbname.".accdb").";"; $this->db->open($connstr); } function getcolor($user){ $recordSet = $this->db->Execute("SELECT color FROM `User` WHERE Username='".$user."'"); $bob = $recordSet->Fields(0); return $bob; } function checkusers(){ $result = $this->db->Execute("SELECT * FROM user"); while(!$result->EOF){ if(date('dHi')-$rs->Fields(2) > 5){ $this->db->Execute('DELETE FROM User WHERE User = "'.$rs->Fields(0).'"',$this->conn); $this->db->Execute("INSERT INTO Chat (Username,Message) VALUES('Xbgh54tr','<b>".$rs->Fields(0)."</b> has left the chat')",$this->conn); } } } function getmsg($user){ $this->db->Execute("UPDATE `User` SET Tim = '".date('dHi')."' WHERE Username='".$user."'"); $result = $this->db->Execute("SELECT * FROM Chat"); $msg=''; while(!$result->EOF){ if ($result->Fields(0)!='Xbgh54tr') $msg .= $row['user'].' - <font color="#'. $this->getcolor($result->Fields(0)) .'">'. $this->smilie($result->Fields(1)).'</font><br>'; else $msg .= '<font color="#FFFF00">'.$result->Fields(1).'</font><br>'; } $this->checkusers(); return $msg; } function sendmsg($user, $text){ $this->db->Execute("INSERT INTO chat VALUES('".$user."','".$text."')"); } function smilie($text){ $rs = $this->db->Execute("SELECT Smilies FROM Smilies"); while(!$rs->EOF) { $smilies[] = $rs->Fields(0); $images[] = "<img src='smilies/" . $rs->Fields(1) . ".gif'>"; } $text=str_replace($smilies, $images, $text); return $text; } function newuser($user, $color){ $this->db->Execute("INSERT INTO Chat (Username, Message) VALUES('Xbgh54tr','<b>".$user."</b> has joined the chat')"); $date=date('dHi'); $this->db->Execute("INSERT INTO `User` (Username, Color, Tim) VALUES('".$user."','".$color."','".$date."')"); } function changeuser($old, $new){ $this->db->Execute("UPDATE User SET user = '".$new."' WHERE user='".$old."'"); $this->db->Execute("INSERT INTO Chat VALUES('Xbgh54tr','<b>".$old."</b> has changed thier name to <b>".$new."</b>')"); }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/35566-error-object-of-class-variant-could-not-be-converted-to-string/ Share on other sites More sharing options...
trq Posted January 24, 2007 Share Posted January 24, 2007 Can we see some code where you try and use this class?Also, this line....[code=php:0]if(date('dHi')-$rs->Fields(2) > 5){[/code]makes no sense, and within that same method where are you getting $rs from? Link to comment https://forums.phpfreaks.com/topic/35566-error-object-of-class-variant-could-not-be-converted-to-string/#findComment-168469 Share on other sites More sharing options...
fred12ned Posted January 25, 2007 Author Share Posted January 25, 2007 [quote author=thorpe link=topic=123882.msg512689#msg512689 date=1169674078][code=php:0]if(date('dHi')-$rs->Fields(2) > 5){[/code][/quote]$rs should be $resultAll that does is finds out if the user has been inactive for 5 minsI am using it like this[code]<?phprequire('access.php');$con = new conn;$con->connect('database');$pop = $con->getmsg($_GET['user']);echo $pop;?>[/code] Link to comment https://forums.phpfreaks.com/topic/35566-error-object-of-class-variant-could-not-be-converted-to-string/#findComment-168784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.