Re: Usage of class constants inside strings and heredocs [message #170509 is a reply to message #170500] |
Thu, 04 November 2010 09:01 |
Giuseppe Sacco
Messages: 5 Registered: November 2010
Karma:
|
Junior Member |
|
|
Hi all,
just to be sure: when you suggest to use sprintf(), do you mean
something like this?
<?php
class myTable {
const F_CODE = "code";
const F_DESCRIPTION = "description";
const TABLENAME = "lookup";
public function insert($record)
{
// simplified: does not escape strings, does not use prepared
statemnts
$sql = sprintf("INSERT INTO %s (%s,%s) VALUES ('%s', '%s')",
self::TABLENAME, self::F_CODE, self::F_DESCRIPTION,
$record[self::F_CODE], $record[self::F_DESCRIPTION]);
echo $sql;
} // end method insert
} // end class myTable
$record = array(
'code' => 'This is the code',
'description' => 'This is the description',
);
$foo = new myTable;
$foo->insert($record);
?>
|
|
|