Solved

mysql: please explain beginning of this method. Thanks

Posted on 2011-09-28
3
265 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:epifanio67
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 36771445
This is a PHP thing, not a MySQL thing. See the printf and sprintf documentations.
0
 
LVL 8

Assisted Solution

by:rationalboss
rationalboss earned 250 total points
ID: 36813932
When you do something like this:

echo sprintf("Hello %s (%s) -- %d","epifanio","how are you?",33); //the output will be Helo epfianio (how are you?) -- 33

%s  -- string
%d / %i -- decimal/integer
%f -- float

for more information, check the php manual: www.php.net/sprintf

printf also does the same except that it outputs it directly to the browser. sprintf returns the text so you can echo it yourself or store in a variable.

you are right about the data coming from the second parameter of sprintf.
0
 

Author Closing Comment

by:epifanio67
ID: 36815737
got it... thank you experts
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with query 3 31
SELECT query on two levels (detail and summary) 13 57
table joins in qry 17 61
Using SQL*PLUS issue with where statement with trunc function 3 28
As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question