Solved

mysql: please explain beginning of this method. Thanks

Posted on 2011-09-28
3
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

630 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