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


PHP DataManager::insert方法代码示例

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


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

示例1: controller_create

 public function controller_create($args)
 {
     $vars["success"] = null;
     $vars["varname"] = "newdemo";
     $tablename = "demos";
     $objkey = "demoname";
     if (!empty($args["category"]) || !empty($args["newcategory"])) {
         $vars["varname"] = "newcategory";
         $tablename = "demo_categories";
         $objkey = "category";
     }
     if (!empty($args[$vars["varname"]])) {
         $newobj = $args[$vars["varname"]];
         $newobjid = $newobj[$objkey];
         if (!empty($newobj[$objkey]) && !empty($newobj["title"])) {
             $vars["success"] = DataManager::insert("db.demos.{$newobjid}", $tablename, $newobj);
             if (!$vars["success"]) {
                 // insert failed, try an update
                 $vars["success"] = DataManager::update("db.demos.{$newobjid}", $tablename, $newobj, array($objkey => $newobjid));
             }
         }
         $vars["demo"] = $newobj;
     } else {
         if (!empty($args["category"])) {
             $vars["varname"] = "newcategory";
             $demos = DataManager::fetch("db.demos.{$args['category']}", "demo_categories", array($objkey => $args["category"]));
             $vars["demo"] = $demos[0];
         } else {
             if (!empty($args["demoname"])) {
                 $demos = DataManager::fetch("db.demos.{$args['demoname']}", "demos", array("demoname" => $args["demoname"]));
                 $vars["demo"] = $demos[0];
             }
         }
     }
     return $this->GetComponentResponse("./create.tpl", $vars);
 }
开发者ID:jbaicoianu,项目名称:elation,代码行数:36,代码来源:demos.php

示例2: Update

 /**
  * Update a specific config entry (diffs only)
  *
  * @param string $name name of config to update
  * @param array $newcfg new configuration object to compare with
  * @return array
  */
 function Update($name, $newcfg, $role = "", $deletecfg = null, $skipLocalConfig = false, $addedcfg = null)
 {
     $ret = false;
     $updaterevision = false;
     $this->Load($name, $role, $skipLocalConfig);
     $oldcfg = $this->configs[$name];
     $cobrandid = $oldcfg["cobrandid"];
     $oldrevision = $oldcfg["revision"];
     //remove revision key / value pair. It should be auto incremented
     unset($oldcfg["revision"]);
     //unset($newcfg["revision"]);
     /*
     $diff = array_diff_assoc_recursive($newcfg, $oldcfg);
     $configupdates = $this->FlattenConfig($diff);
     */
     $configdeletes = $this->FlattenConfig($deletecfg);
     if (count($newcfg) > 0) {
         foreach ($newcfg as $k => $v) {
             Logger::Debug('ConfigManager Update: [' . $name . ' ' . $cobrandid . ' ' . $role . '] ' . $k . ' = ' . $v["value"] . ' : ' . $v["type"]);
             $response = DataManager::Query("db.config.cobrand_config.{$name}-{$k}:nocache", "UPDATE config.cobrand_config SET value=:value, type=:type, modified_time=:timestamp WHERE name=:name AND cobrandid=:cobrandid AND role=:role", array(":value" => $v["value"], ":type" => $v["type"], ":name" => $k, ":cobrandid" => $cobrandid, ":role" => $role, ":timestamp" => unixtime_milli()));
             if (!empty($response) && $response->numrows > 0) {
                 $ret = true;
             }
         }
         $updaterevision = true;
     }
     // process the inserts en-masse
     if (count($addedcfg) > 0) {
         $keyvalues = array();
         foreach ($addedcfg as $k => $v) {
             $keyvalues[] = array("ccid" => md5int64($role . '-' . $cobrandid . '-' . $k), "cobrandid" => $cobrandid, "name" => $k, "value" => $v["value"], "type" => $v["type"], 'role' => $role);
         }
         if (!empty($keyvalues)) {
             $query = DataManager::insert("db.config.cobrand_config.{$name}-{$k}:nocache", "config.cobrand_config", $keyvalues);
             $ret |= true;
         }
         $updaterevision = true;
     }
     // process the deletes
     if (count($configdeletes) > 0) {
         /*
         foreach ($configdeletes as $k=>$v) {
           if ($configdeletes[$k]) {
             $query = DataManager::query("db.config.cobrand_config.delete.{$name}-{$k}:nocache",
                                          "DELETE FROM config.cobrand_config WHERE name=:name AND cobrandid=:cobrandid and role=:role",
                                          array(":name" => $k, ":cobrandid" => $cobrandid, ":role" => $role));
             $ret |= true;
           }
         }
         */
         /* FIXME - code above deletes one-by-one, this code deletes en-masse.  Should we switch to this instead? */
         /* yes i believe so. -lazarus */
         $deletes = array();
         foreach ($configdeletes as $k => $v) {
             if ($v == 1) {
                 $deletes[] = "'{$k}'";
             }
         }
         if (!empty($deletes)) {
             $deletestr = implode(",", $deletes);
             // FIXME - doesn't PDO have a better way to handle "IN ('blah','asdf') type statements?
             $query = DataManager::query("db.config.cobrand_config.delete.{$name}-{$k}:nocache", "DELETE FROM config.cobrand_config WHERE cobrandid=:cobrandid AND role=:role AND name IN ({$deletestr})", array(":cobrandid" => $cobrandid, ":role" => $role));
             $ret |= true;
         }
         $updaterevision = true;
     }
     if ($updaterevision) {
         $this->UpdateRevision($cobrandid, $role);
         DataManager::CacheClear("db.config.cobrand_config.{$name}.{$role}");
         DataManager::CacheClear("db.config.version.{$name}.{$role}");
     }
     if ($ret) {
         DataManager::CacheClear("db.config.cobrand_config.{$name}.{$role}");
     }
     return $ret;
 }
开发者ID:ameyer430,项目名称:elation,代码行数:83,代码来源:configmanager_class.php


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