当前位置: 首页>>代码示例>>PHP>>正文


PHP DatabaseConnection::escape方法代码示例

本文整理汇总了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
//.........这里部分代码省略.........
开发者ID:Goodgulf,项目名称:nodemesh,代码行数:101,代码来源:class.Node.php

示例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);
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:20,代码来源:simpleql.php


注:本文中的DatabaseConnection::escape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。