Link to home
Start Free TrialLog in
Avatar of epifanio67
epifanio67

asked on

mysql: please explain beginning of this method. Thanks

Hello Experts,

what does this mean?

' ( %s ) VALUES ( %s ) '

in the beginning of the method below? this is string (single quotes)... the values seems to come from the second object param...

thanks,

function insertObject( $table, &$object, $keyName = NULL ) {
		
$fmtsql = 'INSERT INTO '.$this->nameQuote($table).' (%s)VALUES(%s)'; //I am not sure how these values are obtained to do an insert

$fields = array();
	foreach (get_object_vars( $object ) as $k => $v) {
		if (is_array($v) or is_object($v) or $v === NULL) {
				continue;
			}
		if ($k[0] == '_') { // internal field
				continue;
		}
		$fields[] = $this->nameQuote( $k );
		$values[] = $this->isQuoted( $k ) ? $this->Quote( $v ) : (int) $v;
		}
		$this->setQuery( sprintf( $fmtsql, implode( ",", $fields ) ,  implode( ",", $values ) ) );
		if (!$this->query()) {
			return false;
		}
		$id = $this->insertid();
		if ($keyName && $id) {
			$object->$keyName = $id;
		}
		return true;
	}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of epifanio67
epifanio67

ASKER

got it... thank you experts