QuickBooks/Driver/Sql.php
public function insert($table, $object, $discov_and_resync = true)
	{
		$sql = '';
		$avail = $this->fields($table, true);		// List of available fields
		$fields = array();
		$values = array();

		if (is_object($object))
		{
			$object = $object->asArray();
		}

		// Case folding support
		if ($this->foldsToLower())
		{
			$object = array_change_key_case($object, CASE_LOWER);
		}
		else if ($this->foldsToUpper())
		{
			$object = array_change_key_case($object, CASE_UPPER);
		}

		if (!is_array($object) or !is_array($avail))
		{
			print('ERROR SAVING [[' . "\n");
			print('TABLE: ' . $table . "\n");
			print_r($object);
			print_r($avail);
			print(']]');
			exit;
		}

		// Merge by keys to make sure we don't INSERT any fields that don't exist in this schema
		$object = array_intersect_key($object, $avail);

		/*
		foreach ($object as $field => $value)
		{
			$fields[] = $field;

			////
			//// * POSSIBLE FIX FOR BELOW CODE *
			////
////if ( strlen((int) $value) == strlen($value) and
////((int)$value) == $value and
////ctype_digit($value) )
			////

			//// Commented out because doing this to very large integers (i.e. ItemRef/FullName is a large integer SKU) causes integer overflow
			////if (strlen((int) $value) == strlen($value))
			////{
			////	$values[] = (int) $value;
			////}
			////else
			////{
				$values[] = " '" . $this->_escape($value) . "' ";
			////}
		}
		*/

		//print_r($object);

		foreach ($object as $field => $value)
		{
			$fields[] = $field;

			if (ctype_digit($value) and
				strlen((float) $value) == strlen($value) and
				((float)$value) == $value and
				strlen($value) < 16)
			{
				// Number, cast as float to avoid integer overflow
                $values[] = (float) $value;
			}
		    else if ($value != '')
            {
                // String value, put it in quotes.
                $values[] = " '" . $this->_escape($value) . "' ";
            }
            else if ($value === 0)
            {
            	$values[] = $value;
            }
            else
            {
                // Empty string value, don't insert
                array_pop($fields);
            }
		}

		$sql = "INSERT INTO " . $this->_escape($table) . " ( " . implode(', ', $fields) . " ";

		if ($discov_and_resync)
		{
			$sql .= ", " . QUICKBOOKS_DRIVER_SQL_FIELD_DISCOVER . ", " . QUICKBOOKS_DRIVER_SQL_FIELD_RESYNC . " ";
		}

		$sql .= " ) VALUES ( " . implode(', ', $values) . " ";

		if ($discov_and_resync)
		{
			$sql .= ", '" . date('Y-m-d H:i:s') . "', '" . date('Y-m-d H:i:s') . "' ";
		}

		$sql .= " ); ";

		//print_r($object);
		//die($sql);

		/*
		if ($table == 'pricemodel_tierset')
		{
			print_r($object);
			print($sql);
			exit;
		}
		*/

		$errnum = 0;
		$errmsg = '';
		return $this->_query($sql, $errnum, $errmsg);
	}
public function insert($table, $object, $discov_and_resync = true)
	{
		$sql = '';
		$avail = $this->fields($table, true);		// List of available fields
		$fields = array();
		$values = array();

		if (is_object($object))
		{
			$object = $object->asArray();
		}

		// Case folding support
		if ($this->foldsToLower())
		{
			$object = array_change_key_case($object, CASE_LOWER);
		}
		else if ($this->foldsToUpper())
		{
			$object = array_change_key_case($object, CASE_UPPER);
		}

		if (!is_array($object) or !is_array($avail))
		{
			print('ERROR SAVING [[' . "\n");
			print('TABLE: ' . $table . "\n");
			print_r($object);
			print_r($avail);
			print(']]');
			exit;
		}

		// Merge by keys to make sure we don't INSERT any fields that don't exist in this schema
		$object = array_intersect_key($object, $avail);

		/*
		foreach ($object as $field => $value)
		{
			$fields[] = $field;

			////
			//// * POSSIBLE FIX FOR BELOW CODE *
			////
////if ( strlen((int) $value) == strlen($value) and
////((int)$value) == $value and
////ctype_digit($value) )
			////

			//// Commented out because doing this to very large integers (i.e. ItemRef/FullName is a large integer SKU) causes integer overflow
			////if (strlen((int) $value) == strlen($value))
			////{
			////	$values[] = (int) $value;
			////}
			////else
			////{
				$values[] = " '" . $this->_escape($value) . "' ";
			////}
		}
		*/

		//print_r($object);

		foreach ($object as $field => $value)
		{
			$fields[] = $field;

			if (ctype_digit($value) and
				strlen((float) $value) == strlen($value) and
				((float)$value) == $value and
				strlen($value) < 16)
			{
				// Number, cast as float to avoid integer overflow
                $values[] = (float) $value;
			}
		    else if ($value != '')
            {
                // String value, put it in quotes.
                $values[] = " '" . $this->_escape($value) . "' ";
            }
            else if ($value === 0)
            {
            	$values[] = $value;
            }
            else
            {
                // Empty string value, don't insert
                array_pop($fields);
            }
		}

		$sql = "INSERT INTO " . $this->_escape($table) . " ( " . implode(', ', $fields) . " ";

		if ($discov_and_resync)
		{
			$sql .= ", " . QUICKBOOKS_DRIVER_SQL_FIELD_DISCOVER . ", " . QUICKBOOKS_DRIVER_SQL_FIELD_RESYNC . " ";
		}

		$sql .= " ) VALUES ( " . implode(', ', $values) . " ";

		if ($discov_and_resync)
		{
			$sql .= ", '" . date('Y-m-d H:i:s') . "', '" . date('Y-m-d H:i:s') . "' ";
		}

		$sql .= " ); ";

		//print_r($object);
		//die($sql);

		/*
		if ($table == 'pricemodel_tierset')
		{
			print_r($object);
			print($sql);
			exit;
		}
		*/

		$errnum = 0;
		$errmsg = '';
		return $this->_query($sql, $errnum, $errmsg);
	}
Insert a new record into an SQL table

@param string $table
@param object $object
@return boolean