Solved

mysql: please explain beginning of this method. Thanks

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

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
got it... thank you experts
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

'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 …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now