2 Replies - 2725 Views - Last Post: 01 October 2011 - 06:49 PM Rate Topic: -----

#1 creativecoding  Icon User is online

  • Hash != Encryption
  • member icon


Reputation: 922
  • View blog
  • Posts: 3,195
  • Joined: 19-January 10

Object of class stdClass could not be converted to string

Posted 01 October 2011 - 06:17 PM

I get this error:

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


For this function:
public function syncvars(){
		require_once("inc/db.class.php");
		$db = new db();
		$mysqli = $db->connect();
		$result = $mysqli->query("SELECT DISTINCT varname FROM data");
		$vars = array();
		while($rr = $result->fetch_object()){
			$vars[] = $rr;
		}
		$sql = "";
		foreach($vars as $x){
			if($stmt = $mysqli->prepare("DELETE FROM variables WHERE name=?")){
				$stmt->bind_param("s", $x);
				$stmt->execute();
			} else {
				$this->log("status", "failed");
				$this->log("fineStatus", $mysqli->error);
				return false;
			}
			if($stmt = $mysqli->prepare("INSERT INTO variables(name) VALUES(?)")){
				$stmt->bind_param('s', $x);
				$stmt->execute();
			} else {
				$this->log("status", "failed");
				$this->log("fineStatus", $mysqli->error);
				return false;
			}
		}
	}



the error is on line 14

Is This A Good Question/Topic? 0
  • +

Replies To: Object of class stdClass could not be converted to string

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 943
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: Object of class stdClass could not be converted to string

Posted 01 October 2011 - 06:38 PM

You're trying to convert an object to a string. The error is actually Line 13. It should be $x->varname
Was This Post Helpful? 1
  • +
  • -

#3 creativecoding  Icon User is online

  • Hash != Encryption
  • member icon


Reputation: 922
  • View blog
  • Posts: 3,195
  • Joined: 19-January 10

Re: Object of class stdClass could not be converted to string

Posted 01 October 2011 - 06:49 PM

View Postcodeprada, on 02 October 2011 - 02:38 AM, said:

You're trying to convert an object to a string. The error is actually Line 13. It should be $x->varname


ah, thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1