Solved

mysql: please explain beginning of this method. Thanks

Posted on 2011-09-28
3
261 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query resolving a string conversion issue 26 42
Select record with the most recent date 14 54
Email Header Detail 12 53
SQL Use Distinct with two fields 3 7
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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