public function insertObject($table, &$object, $key = null)
	{
		// Initialise some variables
		$fields = [];
		$values = [];
		$binds  = [];

		// Create the base insert statement
		$statement = 'INSERT INTO ' . $this->quoteName($table) . ' (%s) VALUES (%s)';

		// Iterate over the object variables to build the query fields and values
		foreach (get_object_vars($object) as $k => $v)
		{
			// Only process non-null scalars
			if (is_array($v) or is_object($v) or $v === null)
			{
				continue;
			}

			// Ignore any internal fields
			if ($k[0] == '_')
			{
				continue;
			}

			// Prepare and sanitize the fields and values for the database query
			$fields[] = $this->quoteName($k);
			$values[] = '?';
			$binds[]  = $v;
		}

		// Set the query and execute the insert
		$this->prepare(sprintf($statement, implode(',', $fields), implode(',', $values)))
		     ->bind($binds);

		if (!$this->execute())
		{
			return false;
		}

		// Update the primary key if it exists
		$id = $this->insertid();
		if ($key && $id)
		{
			$object->$key = $id;
		}

		return true;
	}
public function insertObject($table, &$object, $key = null)
	{
		// Initialise some variables
		$fields = [];
		$values = [];
		$binds  = [];

		// Create the base insert statement
		$statement = 'INSERT INTO ' . $this->quoteName($table) . ' (%s) VALUES (%s)';

		// Iterate over the object variables to build the query fields and values
		foreach (get_object_vars($object) as $k => $v)
		{
			// Only process non-null scalars
			if (is_array($v) or is_object($v) or $v === null)
			{
				continue;
			}

			// Ignore any internal fields
			if ($k[0] == '_')
			{
				continue;
			}

			// Prepare and sanitize the fields and values for the database query
			$fields[] = $this->quoteName($k);
			$values[] = '?';
			$binds[]  = $v;
		}

		// Set the query and execute the insert
		$this->prepare(sprintf($statement, implode(',', $fields), implode(',', $values)))
		     ->bind($binds);

		if (!$this->execute())
		{
			return false;
		}

		// Update the primary key if it exists
		$id = $this->insertid();
		if ($key && $id)
		{
			$object->$key = $id;
		}

		return true;
	}
public function insertObject ( $ table , & $ object , $ key = null ) { // Initialise some variables $ fields = [ ] ; $ values = [ ] ; $ binds = [ ] ; // Create the base insert statement $ statement = 'INSERT INTO ' . $ this -> quoteName ( $ table ) . ' (%s) VALUES (%s)' ; // Iterate over the object variables to build the query fields and values foreach ( get_object_vars ( $ object ) as $ k => $ v ) { // Only process non-null scalars if ( is_array ( $ v ) or is_object ( $ v ) or $ v === null ) { continue ; } // Ignore any internal fields if ( $ k [ 0 ] == '_' ) { continue ; } // Prepare and sanitize the fields and values for the database query $ fields [ ] = $ this -> quoteName ( $ k ) ; $ values [ ] = '?' ; $ binds [ ] = $ v ; } // Set the query and execute the insert $ this -> prepare ( sprintf ( $ statement , implode ( ',' , $ fields ) , implode ( ',' , $ values ) ) ) -> bind ( $ binds ) ; if ( ! $ this -> execute ( ) ) { return false ; } // Update the primary key if it exists $ id = $ this -> insertid ( ) ; if ( $ key && $ id ) { $ object -> $ key = $ id ; } return true ; }
Inserts a row into a table based on an object's properties

@param   string  $table    The name of the database table to insert into
@param   object  &$object  A reference to an object whose public properties match the table fields
@param   string  $key      The name of the primary key. If provided the object property is updated
@return  bool
@since   2.0.0
Inserts a row into a table based on an object s properties