src/Model3/Db/Table.php
public function insert($data)
	{
		//var_dump($data);
		unset($this->_error);
		if(is_array($data))
		{
			$fields = '';
			$values = '';
			reset($data);
			for($counter = 0, $maxIndex = count($data), $valid = true; $counter < $maxIndex && $valid == true; $counter ++)
			{
				$elementKey = key($data);
				$elementKey = $this->_db->escape($elementKey);
				$valid = in_array($elementKey, $this->_fields);
				if($valid == true)
				{
                    $element = $data[$elementKey];
                    $element = $this->_db->escape($element);
					if(is_object($element) == true)
					{
						$valid = false;
						$this->_error = 'field: '.$elementKey.'is an object (this method just accept strings)';
					}
					else
					{
						if(is_numeric($element) == false)
							$values .= '\''.$element.'\'';
						else
							$values .= $element;
						$fields .= $elementKey;
						if(($counter + 1) < $maxIndex)
						{
							$fields .= ',';
							$values .= ',';
						}
						next($data);
					}
				}
				else
				{
					$this->_error = 'field: '.$elementKey.' is not defined in '.$this->_tableName;
				}
			}
			if($valid == true)
			{
				$this->_query = 'INSERT INTO '.$this->_tableName.'('.$fields.') VALUES('.$values.')';
				if($this->_db->execute($this->_query) !== false)
				{
					return $this->_db->insertId();
				}
				else
				{
					$this->_error = $this->_db->errorStr();
				}
			}
		}
		return false;
	}
public function insert($data)
	{
		//var_dump($data);
		unset($this->_error);
		if(is_array($data))
		{
			$fields = '';
			$values = '';
			reset($data);
			for($counter = 0, $maxIndex = count($data), $valid = true; $counter < $maxIndex && $valid == true; $counter ++)
			{
				$elementKey = key($data);
				$elementKey = $this->_db->escape($elementKey);
				$valid = in_array($elementKey, $this->_fields);
				if($valid == true)
				{
                    $element = $data[$elementKey];
                    $element = $this->_db->escape($element);
					if(is_object($element) == true)
					{
						$valid = false;
						$this->_error = 'field: '.$elementKey.'is an object (this method just accept strings)';
					}
					else
					{
						if(is_numeric($element) == false)
							$values .= '\''.$element.'\'';
						else
							$values .= $element;
						$fields .= $elementKey;
						if(($counter + 1) < $maxIndex)
						{
							$fields .= ',';
							$values .= ',';
						}
						next($data);
					}
				}
				else
				{
					$this->_error = 'field: '.$elementKey.' is not defined in '.$this->_tableName;
				}
			}
			if($valid == true)
			{
				$this->_query = 'INSERT INTO '.$this->_tableName.'('.$fields.') VALUES('.$values.')';
				if($this->_db->execute($this->_query) !== false)
				{
					return $this->_db->insertId();
				}
				else
				{
					$this->_error = $this->_db->errorStr();
				}
			}
		}
		return false;
	}
public function insert ( $ data ) { //var_dump($data); unset ( $ this -> _error ) ; if ( is_array ( $ data ) ) { $ fields = '' ; $ values = '' ; reset ( $ data ) ; for ( $ counter = 0 , $ maxIndex = count ( $ data ) , $ valid = true ; $ counter < $ maxIndex && $ valid == true ; $ counter ++ ) { $ elementKey = key ( $ data ) ; $ elementKey = $ this -> _db -> escape ( $ elementKey ) ; $ valid = in_array ( $ elementKey , $ this -> _fields ) ; if ( $ valid == true ) { $ element = $ data [ $ elementKey ] ; $ element = $ this -> _db -> escape ( $ element ) ; if ( is_object ( $ element ) == true ) { $ valid = false ; $ this -> _error = 'field: ' . $ elementKey . 'is an object (this method just accept strings)' ; } else { if ( is_numeric ( $ element ) == false ) $ values .= '\'' . $ element . '\'' ; else $ values .= $ element ; $ fields .= $ elementKey ; if ( ( $ counter + 1 ) < $ maxIndex ) { $ fields .= ',' ; $ values .= ',' ; } next ( $ data ) ; } } else { $ this -> _error = 'field: ' . $ elementKey . ' is not defined in ' . $ this -> _tableName ; } } if ( $ valid == true ) { $ this -> _query = 'INSERT INTO ' . $ this -> _tableName . '(' . $ fields . ') VALUES(' . $ values . ')' ; if ( $ this -> _db -> execute ( $ this -> _query ) !== false ) { return $ this -> _db -> insertId ( ) ; } else { $ this -> _error = $ this -> _db -> errorStr ( ) ; } } } return false ; }
data is an associative array containing the name of the field and its value
data is an associative array containing the name of the field and its value