本文整理汇总了PHP中DatabaseConnection::escape方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseConnection::escape方法的具体用法?PHP DatabaseConnection::escape怎么用?PHP DatabaseConnection::escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection::escape方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: commit
public function commit(array $attributes)
{
//TODO: move all this logic to the query class
// Get the node type
$type = $this->getType();
// Determine the correct context
if (is_string($attributes['context']))
{
// Use the passed context
$attributes['context'] = MeshTools::GetContextPks($attributes['context']);
}
else if (!$attributes['context'])
{
if ($this->pk)
{
// Bypass context on existing nodes if not explicitly passed in
unset($attributes['context']);
}
else
{
// For new nodes use the default context
$attributes['context'] = (array)MeshTools::GetDefaultContextPk();
if (empty($attributes['context'])) // for non-context setups
{
unset($attributes['context']);
}
}
}
if (! isset($attributes['context']))
{
// Do nothing, bypass context updates
}
else if (1 == count($attributes['context']))
{
$attributes['context'] = $attributes['context'][0];
}
else // @todo New nodes can only have one context
{
throw new Exception('Cannot create node with ambiguous context');
}
// Separate the attirbutes from the links
foreach ($attributes as $key => $value)
{
// Link Nodes if not attributes
if (! $this->_isAttribute($key))
{
// Use only valid node types
if ($this->_isNodeType($key))
{
// Copy the attribute to the links array
$links[$key] = $attributes[$key];
}
else
{
throw new Exception('Cannot link '.$type.' with '.$key.' because type '.$key.' doesn\'t exist.');
}
// Remove all non-attirbutes from the attributes array
unset($attributes[$key]);
}
}
try
{
// First update/insert the attributes
// If the node exists then peform update, otherwise insert
if ($this->pk)
{
// cache the data for this node
$this->_cache->populate($attributes);
$dbc = new DatabaseConnection();
$sql = "UPDATE $type SET ";
foreach ($attributes as $key => $value)
{
$sql .= " $key = '".$dbc->escape($value)."', ";
}
$sql = rtrim($sql, ', ');
$sql .= " WHERE pk = $this->pk";
$dbc->query($sql);
}
else
{
// cache the data for this node
$this->_cache->populate($attributes);
$dbc = new DatabaseConnection();
// Clean the attributes
//.........这里部分代码省略.........
示例2: execute
function execute()
{
$db = new DatabaseConnection();
$stmt = "INSERT INTO " . $this->table . " ";
$rd = array();
foreach ($this->insert[0] as $key => $val) {
$rd[] = $key;
}
$stmt .= "(" . join(',', $rd) . ") VALUES ";
$si = array();
foreach ($this->insert as $row) {
$sr = array();
foreach ($row as $key => $val) {
$sr[] = $db->escape('%s', $val);
}
$si[] = '(' . join(',', $sr) . ')';
}
$stmt .= join(', ', $si);
return $db->insertRow($stmt);
}