english/libraries/joomla/database/database.php
/**
	 * 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    True on success.
	 *
	 * @since   11.1
	 * @throws  DatabaseException
	 */
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    True on success.


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