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


PHP DataBase::escape方法代码示例

本文整理汇总了PHP中DataBase::escape方法的典型用法代码示例。如果您正苦于以下问题:PHP DataBase::escape方法的具体用法?PHP DataBase::escape怎么用?PHP DataBase::escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataBase的用法示例。


在下文中一共展示了DataBase::escape方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: check_category_name

 /**
  * 检查分组名是否存在
  * @param $user_id 联系人ID
  * @param $name 分组名
  * @param $id 分组ID
  * @return bool
  */
 public function check_category_name($user_id, $name, $id)
 {
     $filter = '';
     if (!empty($id)) {
         $filter = "AND id != {$id}";
     }
     $sql = sprintf("SELECT id FROM %s WHERE uid = %d AND category_name = %s %s LIMIT 1", $this->get_table($user_id, 'contact_categories'), $user_id, $this->db->escape($name), $filter);
     $query = $this->db->query($sql);
     if ($query->count()) {
         return TRUE;
     }
     return FALSE;
 }
开发者ID:momoim,项目名称:momo-api,代码行数:20,代码来源:Contact_Mapper.php

示例2: _add_info

 /**
  * 添加电话、邮箱、网址、纪念日、关系、地址等信息
  * @param int $group_id 用户ID
  * @param int $id 联系人分组ID
  * @param int $type 类型
  * @param array $emails 邮箱信息
  * @return array
  */
 private function _add_info($group_id, $id, $type = 'emails', $values, $pref_tel = '')
 {
     $sql = array();
     switch ($type) {
         case 'tels':
             if (!empty($values)) {
                 foreach ($values as $tel) {
                     if (!empty($tel['value'])) {
                         if ($pref_tel and ($tel['value'] == $pref_tel or $tel['pref'] == 1)) {
                             continue;
                         }
                         if ($tel['pref'] == 1) {
                             $pref_tel = $tel['value'];
                         }
                         $tel['type'] = $this->db->escape($tel['type']);
                         $tel['value'] = $this->db->escape($tel['value']);
                         $tel['city'] = $this->db->escape($tel['city']);
                         $sql[] = "INSERT INTO `gcp_tels` (`gid`, `gcid`, `type`, `value`," . " `pref`, `city`) VALUES ('{$group_id}', '{$id}', {$tel['type']} ,{$tel['value']}," . " {$tel['pref']}, {$tel['city']});";
                     }
                 }
             }
             break;
         case 'addresses':
             if (!empty($values)) {
                 foreach ($values as $address) {
                     if (!empty($address['country']) || !empty($address['region']) || !empty($address['city']) || !empty($address['street']) || !empty($address['postal'])) {
                         $address['country'] = $this->db->escape($address['country']);
                         $address['region'] = $this->db->escape($address['region']);
                         $address['city'] = $this->db->escape($address['city']);
                         $address['street'] = $this->db->escape($address['street']);
                         $address['postal'] = $this->db->escape($address['postal']);
                         $address['type'] = $this->db->escape($address['type']);
                         $sql[] = "INSERT INTO `gcp_addresses` (`gid`, `gcid`, `type`, `country`," . " `postal`, `region`, `city`, `street`) VALUES ('{$group_id}', '{$id}', " . $address['type'] . "," . $address['country'] . ", " . $address['postal'] . ", " . $address['region'] . ", " . $address['city'] . ", " . $address['street'] . ");";
                     }
                 }
             }
             break;
         case 'ims':
             if (!empty($values)) {
                 foreach ($values as $im) {
                     if (!empty($im)) {
                         if (in_array(strtolower($im['protocol']), Kohana::config('contact.protocol'), TRUE)) {
                             $im['value'] = $this->db->escape($im['value']);
                             $im['type'] = $this->db->escape($im['type']);
                             $im['protocol'] = $this->db->escape($im['protocol']);
                             $sql[] = "INSERT INTO `gcp_ims` (`gid`, `gcid`, `protocol`, `type`, `value`)\n                            VALUES ('{$group_id}', '{$id}', {$im['protocol']}, {$im['type']}, {$im['value']});";
                         }
                     }
                 }
             }
             break;
         default:
             if (!empty($values)) {
                 foreach ($values as $value) {
                     if (!empty($value['value'])) {
                         $value['type'] = $this->db->escape($value['type']);
                         $value['value'] = $this->db->escape($value['value']);
                         $sql[] = "INSERT INTO `gcp_{$type}` (`gid`, `gcid`, `type`, `value`)\n                        VALUES ('{$group_id}', '{$id}', {$value['type']}, {$value['value']});";
                     }
                 }
             }
             break;
     }
     return $sql;
 }
开发者ID:momoim,项目名称:momo-api,代码行数:73,代码来源:Group_Contact_Mapper.php


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